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: consolidate websocketNetConn implementations#12065

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

Merged
spikecurtis merged 1 commit intomainfromspike/websocket-net-conn
Feb 9, 2024

Conversation

spikecurtis
Copy link
Contributor

Consolidates websocketNetConn from multiple packages in favor of a central one in codersdk

@spikecurtisGraphite App
Copy link
ContributorAuthor

This stack of pull requests is managed by Graphite.Learn more about stacking.

Join@spikecurtis and the rest of your teammates onGraphiteGraphite

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It'd be nice to see a test that the 4MiB payload works. Perhaps we could use functional options to adjust it if needed and then test that it works/errors with different sizes.

@@ -50,7 +50,7 @@ func TestTailnetAPIConnector_Disconnects(t *testing.T) {
if!assert.NoError(t,err) {
return
}
ctx,nc:=websocketNetConn(r.Context(),sws,websocket.MessageBinary)
ctx,nc:=WebsocketNetConn(r.Context(),sws,websocket.MessageBinary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'd prefer to fix this bad use ofr.Context() since someone could look at this and get the wrong idea. (Thewebsocket.Accept invalidatesr.Context() cancellation.)

Suggested change
ctx,nc:=WebsocketNetConn(r.Context(),sws,websocket.MessageBinary)
ctx,nc:=WebsocketNetConn(context.Background(),sws,websocket.MessageBinary)

I know some other places are usingr.Context() viactx := r.Context() too, but this one just seems too explicitly wrong. 😄

Perhaps this is actually a case for movingwebsocket.Accept intocodersdk.WebsocketNetConn as well (or creating a unified function,codersdk.WebsocketAcceptNetConn).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The websocket.Accept invalidates r.Context() cancellation.

I don't understand what it means to "invalidate" a context cancelation.

Are you referring to the idea that once we have a websocket, passingr.Context() is a bit pointless because the context won't get canceled before the underlying TCP connection is closed? I guess that's true enough, but changing it tocontext.Background() doesn't change anything from a functional standpoint.

Are you suggesting we don't accept a context at all?

Copy link
Member

@mafredrimafredriFeb 9, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The context is actually not even tied to the TCP connection, it is tied to the handler which creates a scenario where it’s unlikely to ever be cancelled in a way that matters.

https://pkg.go.dev/net/http#Hijacker

Functionally, you’re right, there’s no difference but this behavior can easily trip anyone up so its usage should be discouraged.

@spikecurtisspikecurtis merged commit1f5a6d5 intomainFeb 9, 2024
@spikecurtisspikecurtis deleted the spike/websocket-net-conn branchFebruary 9, 2024 07:39
@spikecurtisGraphite App
Copy link
ContributorAuthor

Merge activity

@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsFeb 9, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

Assignees

@spikecurtisspikecurtis

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@spikecurtis@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp