Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Emyrk wants to merge5 commits intomainfromstevenmasley/websocket_tracking

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedApr 4, 2023
edited
Loading

This is an idea I had.

The problem is that the CoderdAPI 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.

SoClose()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 callAccept 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 likeWithWebsocketSupport:

varmu sync.Mutex
varwaitGroup sync.WaitGroup

Right now we just duplicate thesync.WaitGroup logic and return aWait() which is just kinda annoying.

This isn't 100% better, but it does handle the tracking:

typeHandleWebsocketfunc(rw http.ResponseWriter,r*http.Request,options*websocket.AcceptOptions,ffunc(conn*websocket.Conn))
// WithWebsocketSupport returns an http.Handler that upgrades
// connections to the "derp" subprotocol to WebSockets and
// passes them to the DERP server.
// Taken from: https://github.com/tailscale/tailscale/blob/e3211ff88ba85435f70984cf67d9b353f3d650d8/cmd/derper/websocket.go#L21
// The accept function is used to accept the websocket connection and allows the caller to
// also affect the lifecycle of the websocket connection. (Eg. to close the connection on shutdown)
funcWithWebsocketSupport(acceptHandleWebsocket,s*derp.Server,base http.Handler) http.Handler {


Thoughts?

@EmyrkEmyrk marked this pull request as ready for reviewApril 4, 2023 22:30
@github-actions
Copy link

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.

@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelApr 13, 2023
@EmyrkEmyrk closed thisApr 13, 2023
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsApr 13, 2023
@github-actionsgithub-actionsbot deleted the stevenmasley/websocket_tracking branchOctober 6, 2023 00:10
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees

@EmyrkEmyrk

Labels
staleThis issue is like stale bread.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp