-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
reverseproxy: Wait for both ends of websocket connections to close #6175
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but concurrency stuff like this isn't one of my strengths. Maybe @mholt should take a look before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks sound. But before I totally approve it, I have a concern about the implications of blocking in finalizeResponse(). I think this blocks the entire HTTP request. (But just this request.) Wouldn't that be problematic?
h.handleUpgradeResponse(logger, rw, req, res) | ||
var wg sync.WaitGroup | ||
h.handleUpgradeResponse(logger, &wg, rw, req, res) | ||
wg.Wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This blocks -- not sure if that's actually a good idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a little bit of delay so that statistics are properly updated. Both ends of the connection are closed when handleUpgradeResponse
returns. If this blocks, go has a serious issue where net.Conn.Close
doesn't unblock Read
or Write
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so you're saying that h.handleUpgradeResponse()
was already blocking, and wg.Wait()
waits until the actual conns are Close()
ed, but otherwise it's basically the same amount of blocking.
In that case, this LGTM.
I just couldn't remember if this goroutine was returning while the hijacked connection kept running to do its copy, or if we blocked in there, but it looks like handleUpgradeResponse has a select that blocks at least for most of the time.
So yeah, if this patch works, and doesn't block much longer, then I think we can merge it.
Thanks!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, does the size still log as 0, with this patch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this patch, sometimes size logs as 0. After this, none does.
Related to 6173.
Websockets will show size 0 even if there are data written because the hijacked connection implements both
WriterTo
andReaderFrom
, and stats are only updated when the copying is done.A log entry is like this:
Wait outside the function so connection cleanup is not affected.