Skip to content

net/http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error #62453

Closed as not planned
@AtlanCI

Description

@AtlanCI

What version of Go are you using (go version)?

$ go version
go 1.20.3 amd64

Does this issue reproduce with the latest release?

This problem is a bit strange, I can't reproduce it The latest version and the version I am currently using.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
It runs in my production environment without any special env

What did you do?

Program Logic

I am writing a storage platform service that accepts HTTP POST requests from users and uploads files through Forms I need to send this Form form to the S3 backend. During this process, I will not read the HTTP Body passed by the user, which is the r.body below, and pass it directly to S3 to achieve pseudo streaming upload Because S3 has some special authentication and other information, I use io. MultiReader() in the following code to add my information to the body and upload it to S3.

I am building a request to initiate a request to the S3 service Please note that I used io.MultiReader() in the sample code I provided. Please ignore it. When I called http.do(req), it returned http2: Transport: cannot retry err [http2: Transport received Server's Graceful shutdown GOAWAY] after Request. Body was written; Define Request. GetBody to avoid this error How should I fix such an error.

My HTTP client configuration

       dialer = &net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
	}
	_s3HTTP = &http.Client{Transport: &http.Transport{
		Proxy:                 http.ProxyFromEnvironment,
		DialContext:           dialer.DialContext,
		ForceAttemptHTTP2:     true,
		MaxIdleConns:          1000,
		IdleConnTimeout:       90 * time.Second,
		TLSHandshakeTimeout:   20 * time.Second,
		ExpectContinueTimeout: 5 * time.Second,
		MaxIdleConnsPerHost:   500,
	}}
   
	// make req
	postUrl := c.url()
	request, err := http.NewRequestWithContext(ctx, http.MethodPost, postUrl, io.MultiReader(bytes.NewReader(b.Bytes()[:fieldLen]), bytes.NewReader(fileNameBuffer.Bytes()[:nameLen]), r.Body))

	if err != nil {
		return nil, fmt.Errorf("http.NewRequestWithContext: %w", err)
	}

	resp, err := c.h.Do(request)
	if err != nil {
                // this is error
		return nil, fmt.Errorf("h.Do(): %w", err)
	}

What did you expect to see?

It should upload files to a service similar to S3 normally. How should I fix this error?

What did you see instead?

It prompts the following error message.

h.Do(): Post "https://eos-xxx.cmecloud.cn/s3-bucket": http2: Transport: cannot retry err [http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions