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: document r.Context().Done() behaviour on cancelled POST request #33340

Open
novalagung opened this issue Jul 29, 2019 · 4 comments

Comments

@novalagung
Copy link

commented Jul 29, 2019

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

$ go version

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env

What did you do?

What did you expect to see?

What did you see instead?


Recently I found this question on stack overflow, the OP asked why the r.Context().Done() channel does not receive any data on cancelled POST request. But it does receive data on cancelled GET request.

I tried to find the relevant explanation on the go doc, but I found nothing. Is this not documented?

@julieqiu julieqiu changed the title documentation about net/http r.Context().Done() behaviour on cancelled POST request net/http: documentation on r.Context().Done() behaviour on cancelled POST request Jul 29, 2019

@julieqiu

This comment has been minimized.

Copy link

commented Jul 29, 2019

A better place to ask this kind of question is golang-nuts. See https://golang.org/wiki/Questions.

@julieqiu julieqiu closed this Jul 29, 2019

@julieqiu julieqiu added the Question label Jul 29, 2019

@novalagung

This comment has been minimized.

Copy link
Author

commented Jul 30, 2019

@julieqiu I think you are missing my point. I'm not asking about the answer. I have the answer already, and even in the [stackoverflow]https://stackoverflow.com/questions/57246852 it's also answered.

But the things it the answer is not documented in any golang doc. This might cause some confusion.

@novalagung

This comment has been minimized.

Copy link
Author

commented Jul 30, 2019

The net/http server checks for closed connections by reading the connection. No reads are started until the application starts reading the request body (if any).

What I mean is above statement. I think it's need to be documented.

On GET client request, when the request is cancelled from the client side then immediately r.Context().Done() channel receives a value. But on POST request, it does not.

On POST client request, the r.Context().Done() never receive any value, unless in the handler there is a read process from r.Body and during that reading process the request is cancelled by the client. Then only that the the channel will receive a value.

@julieqiu

This comment has been minimized.

Copy link

commented Jul 31, 2019

@novalgung sorry for the confusion. It seems like this is the correct behavior,
but perhaps someone with net/http expertise should decide if this needs to be
documented.

/cc @dmitshur @bradfitz

@julieqiu julieqiu reopened this Jul 31, 2019

@andybons andybons changed the title net/http: documentation on r.Context().Done() behaviour on cancelled POST request net/http: document r.Context().Done() behaviour on cancelled POST request Aug 12, 2019

@andybons andybons removed the Question label Aug 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.