-
Notifications
You must be signed in to change notification settings - Fork 112
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
Feature: Return error if ResponseWriter does not implement Flush() for streaming RPCs. #393
Comments
Great idea! We can definitely make this better.
Re: your comments on this, it's unfortunately impossible to add new methods to |
Not a solution necessarily, but go1.20 is attempting to address this with their new http.ResponseController. https://pkg.go.dev/net/http@master#ResponseController |
Of course; that issue is the wishlist for backwards incompatible net/http changes in Go 2.
Nice. Maybe instead of my suggestion, it'd be better if they adopted Unwrap as part of the |
🤦🏽♂️ I really ought to read more carefully (or avoid writing in the wee hours of the night). Mea culpa. |
The `http.Flusher` interface isn't part of the `http.ResponseWriter` interface, but it's implemented by the HTTP/1 and HTTP/2 writers provided by the standard library. It's also critical to Connect: streaming handlers must flush messages to ensure that the client receives them. This PR adds a check for unflushable response writers; when the response writer for a streaming procedure can't be flushed, we now return an explicit error instead of hanging. Fixes #393.
Is your feature request related to a problem? Please describe.
If you wrap your
http.ResponseWriter
in middleware before handing to connect go, you may wind up not exposing thehttp.Flusher
interface, leading to calls toSend
not actually flushing thehttp.ResponseWriter
buffer and thus the connection appearing to "hang".Describe the solution you'd like
This problem is tricky to detect and debug because it often works correctly; it only fails in some cases when using streaming RPCs. In an effort to make it harder to footgun oneself, I request that connect-go detect this situation and return an error from a streaming
Send
call.Describe alternatives you've considered
Instead of returning an error, one could panic: this would make it much more noticeable. However, it is unclear if this is worse or better than unexpectedly hanging in production. I think returning an error that can be handled is at least obviously better. One could also make the case for some kind of warning message, but I'm not sure if there's a good way to do that (and perhaps, it's just not loud enough.)
Additional context
Apparently, the buf cli ran into this issue too, when migrating to Connect. It's a common footgun in Go. Maybe Go itself could be improved? I left some thoughts on golang/go#5465.
The text was updated successfully, but these errors were encountered: