- Notifications
You must be signed in to change notification settings - Fork1k
chore: Refactor accepting websocket connections to track for close#7008
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This Pull Request is becoming stale. In order to minimize WIP, prevent merge conflicts and keep the tracker readable, I'm going close to this PR in 3 days if there isn't more activity. |
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
This is an idea I had.
The problem is that the Coderd
API
struct callsWait()
on a waitgroup for all websockets to close before theClose()
method returns. TheClose()
method callscancel
on the parent context, but this context is not actually controlling the lifecycle of the individual request for a given websocket.So
Close()
does not tell a websocket to end. It was achieving this because the parent context is tied to*wsconncache.Cache
which kills the tailnet connections from the parent context.To make this work more directly, I implementedActiveWebsockets. This struct takes the parent context. When you call
Accept
on this struct, it launches a go routine that will force close the websocket if the parent context is cancelled. This all happens when you callClose()
on theActiveWebsocket
struct.This also means we can pass this struct in places like
WithWebsocketSupport
:coder/tailnet/derp.go
Lines 21 to 22 inbf64a43
Right now we just duplicate the
sync.WaitGroup
logic and return aWait()
which is just kinda annoying.This isn't 100% better, but it does handle the tracking:
coder/tailnet/derp.go
Lines 13 to 21 in15ed467
Thoughts?