-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http/fcgi: request context not canceled on aborted connection #71344
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
Comments
I suppose it can be wired up to FCGI_ABORT_REQUEST, but is there a server implementation that supports it? nginx apparently doesn't. |
That would only help the case of graceful shutdowns (which I can see as a feature request). It will not solve the issue of a connection getting killed, be it by a user's client or a reverse proxy. That is the issue I'm seeing as a bug - the context has no correlation to the request or underlying transport. |
FastCGI multiplexes multiple client->proxy connections to fewer proxy->fastcgi connections. |
Thanks for the quick response. There would still be an issue with the proxy shutting down, right? Also, as far as I can tell, it isn't mandatory to multiplex requests, so non-multiplexed connections getting killed is still an issue. But I think you're right in that it won't help solve the case when an end-user kills a request when using a multiplexing reverse proxy, that would probably require FCGI_ABORT_REQUEST. |
While it is possible for the proxy to open a new connection per client connection, I believe none of them will do so as then fastcgi would be pointless. Multiplexing is an inherent part of the protocol, requests sent/received are framed by unique request IDs over the underlying connection. |
From what I can gather nginx doesn't support multiplexing. It doesn't seem to be supported by mod_fastcgi or mod_proxy_fcgi either. Lighttpd doesn't support multiplexing either. Granted, a lot of search results are rather old and things might have changed. HAProxy does support multiplexing. Nginx can be instructed to keep a connection alive, though. As can Apache. But none of them use it as a default behavior as far as I can tell. I'd therefore argue that closing connections is a valid and common use case of FCGI and as the fcgi package doesn't document it as a limitation and as it reuses the http package's request type that does document the expectations of the context, this is is an issue. |
@seankhliao Have you had the chance to reconsider this issue? |
Go version
go version go1.23.4 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
Start an FCGI server.
Using an FCGI client, or a reverse proxy like Apache with FCGI support, issue a request to the server and then close the request. Unfortunately the code for this can get quite verbose as the package only implements the server parts and I'm not sure it provides much context in this case.
What did you see happen?
The string
Done with slow operation
is never printed as the context is never canceled.What did you expect to see?
According to the documentation on the http request's context field, the context should be set and canceled when the connection closes or the server closes. As I haven't found any documentation in the fcgi package stating otherwise, I expect the same to be true.
From what I can tell, the issue comes from the fcgi package never setting a context that corresponds to the incoming connection. It relies on the default
context.Background()
returned byhttp.Request.Context
if it'snil
.go/src/net/http/fcgi/child.go
Lines 292 to 302 in 40b3c0e
This makes the fcgi package difficult to use when web clients are involved as there's seemingly no way to react on aborted / closed requests, making it difficult to stop ongoing work.
The text was updated successfully, but these errors were encountered: