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

SebastiaanKlippert opened this issue Jan 3, 2017 · 4 comments


Copy link

@SebastiaanKlippert SebastiaanKlippert commented Jan 3, 2017

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


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


What did you do?

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

package main

import (

func main(){

	req, err := http.NewRequest("GET", "", http.NoBody)
	if err != nil {

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


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


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
Copy link

@rakyll rakyll commented Jan 3, 2017

/cc @bradfitz

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

@bradfitz 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.

Copy link

@gopherbot gopherbot commented Jan 4, 2017

CL mentions this issue.

@gopherbot gopherbot closed this in 2815045 Jan 4, 2017
Copy link

@kevinburke kevinburke commented Jan 5, 2017

so that's why my DEBUG_HTTP_TRAFFIC flag has been dumping chunked requests! thanks for the patch!

@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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.