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: wrong error on canceled http request #11020

Closed
alicebob opened this issue Jun 1, 2015 · 3 comments
Closed

net/http: wrong error on canceled http request #11020

alicebob opened this issue Jun 1, 2015 · 3 comments
Milestone

Comments

@alicebob
Copy link
Contributor

alicebob commented Jun 1, 2015

when I cancel an outstanding http request (happens to be to ElasticSearch) using http.Transport.CancelRequest() I get the 'net/http: transport closed before response was received' error. But I would expect the 'net/http: request canceled' error.

go version devel +df2809f (master as of now)

Not completely understanding the net/http code this fixes it for me:

--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -1191,7 +1191,11 @@ WaitResponse:
                                        fn()
                                }
                        default:
-                               re = responseAndError{err: errClosed}
+                               err := errClosed
+                               if pc.isCanceled() {
+                                       err = errRequestCanceled
+                               }
+                               re = responseAndError{err: err}
                        }
                        break WaitResponse
                case <-respHeaderTimer:
@ianlancetaylor ianlancetaylor changed the title wrong error on canceled http request net/http: wrong error on canceled http request Jun 1, 2015
@alicebob
Copy link
Contributor Author

alicebob commented Jun 2, 2015

This shows the problem:

https://gist.github.com/alicebob/6b286c4678790fa546f8

Vanilla master:

harmen@deadpixel:/tmp$ go run -v b.go 
command-line-arguments
2015/06/02 11:34:12 Get http://localhost:12345/: net/http: transport closed before response was received
exit status 1

With the patch:

harmen@deadpixel:/tmp$ go run -v b.go 
command-line-arguments
2015/06/02 11:36:31 Get http://localhost:12345/: net/http: request canceled
exit status 1

@gopherbot
Copy link

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

@mikioh mikioh modified the milestones: Go1.5, Go1.5Maybe Jul 28, 2015
@alicebob
Copy link
Contributor Author

Great, thanks!

@golang golang locked and limited conversation to collaborators Aug 5, 2016
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