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
question: why does the http server still handle request in ServeHTTP after server.Close or server.Shutdown #31438
Comments
Please summarize the relevant properties of those snippets — they don't compile, and it's not obvious what the elided code does or how that interacts with the call to Note per https://golang.org/pkg/net/http/#Server.Close:
Also note that closing a connection does not terminate any associated goroutine running So the details of what those nested servers are actually doing are very important, as are the details about when exactly you expect |
Thanks for your reply.
First we create an object of type Those requests are used for loading some business data from DB. After serving all the http requests we call Then we expect the server will not recv the request from any client. As you say
we expect that the http.Server should return some error code to indicate it had been stoped during the time we call But we still got http request which was handled by Thanks. |
If you want the server to shut down gracefully, you can use the |
@pingworld did this adequately answer your question? |
Thanks, we have no other questions! We have solved this problem! All requests have been processed after waiting for several seconds when close the whole app. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I put some code snippets on here.
What did you expect to see?
The http server will not call "(w *WebSvrImpl) ServeHTTP" after we call "(w *WebSvrImpl) Close()". And the http server should return some special error code. e.g. 404?
What did you see instead?
The http server still returns response with http status code 200 and empty body.
We had known the response with empty body is caused by "(w *WebSvrImpl) ServeHTTP" which will not process when "w.closed.Get()" is true.
But why the net/http framework still call ServeHTTP() when we had called the Close() or Shutdown()?
Thanks for your reply!
The text was updated successfully, but these errors were encountered: