Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: HTTP request hangs when dumping non-nil body using httputil.DumpRequestOut #18506

Closed
SebastiaanKlippert opened this issue Jan 3, 2017 · 4 comments
Milestone

Comments

@SebastiaanKlippert
Copy link

SebastiaanKlippert commented Jan 3, 2017

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

go1.8beta2

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

windows/amd64

What did you do?

When running below sample program the program hangs on http.DefaultClient.Do(req)

package main

import (
	"net/http"
	"log"
	"net/http/httputil"
)

func main(){

	req, err := http.NewRequest("GET", "https://start.exactonline.nl/api/v1/current/Me", http.NoBody)
	if err != nil {
		log.Fatal(err)
	}

	rdata, err := httputil.DumpRequestOut(req, true)
	if err != nil {
		log.Fatal(err)
	}

	log.Println(string(rdata))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	log.Println(resp.Status)
}

What did you expect to see?

401 Unauthorized

What did you see instead?

Nothing (hangs for minutes)

Other info

I expect this also has something to do with the server side because when using a different URL everything is OK.

But since this code runs fine on Go 1.7.3 and earlier I expect it is a bug in 1.8.
Note: In the go1.7 code we use a new(bytes.Buffer) instead of http.NoBody in a function that does GET, PUT and POST requests, so only in the GET requests will have an empty buffer.

  • The program works when compiling in versions < 1.8beta1
  • The program works when setting the body to nil
  • The program also works if you do not dump the request

Possibly related to #18117 ?

@rakyll rakyll changed the title 1.8beta2: HTTP request hangs when dumping non-nil body using httputil.DumpRequestOut net/http: HTTP request hangs when dumping non-nil body using httputil.DumpRequestOut Jan 3, 2017
@rakyll rakyll added this to the Go1.8 milestone Jan 3, 2017
@rakyll
Copy link
Contributor

rakyll commented Jan 3, 2017

/cc @bradfitz

@bradfitz bradfitz self-assigned this Jan 4, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Jan 4, 2017

I verified that this was already fixed by 6e36811 which makes me feel better about that fix.

I'll send out a second minor fix to httputil to recognize NoBody specially.

@gopherbot
Copy link

CL https://golang.org/cl/34814 mentions this issue.

@kevinburke
Copy link
Contributor

so that's why my DEBUG_HTTP_TRAFFIC flag has been dumping chunked requests! thanks for the patch! https://github.com/kevinburke/rest/blob/master/client.go#L110-L134

@golang golang locked and limited conversation to collaborators Jan 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants