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: add support for one-way websockets to backend#16853

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
Parkreiner merged 11 commits intomainfrommes/one-way-ws-01
Mar 28, 2025

Conversation

Parkreiner
Copy link
Member

@ParkreinerParkreiner commentedMar 7, 2025
edited
Loading

Closes#16775
Part 1/2, with#16855 handling the frontend changes

Changes made

  • AddedOneWayWebSocket function that establishes WebSocket connections that don't allow client-to-server communication
  • Added tests for the new function
  • Updated API endpoints to make new WS-based endpoints, and mark previous SSE-based endpoints as deprecated
  • Updated existing SSE handlers to use the same core logic as the new WS handlers

@Parkreiner
Copy link
MemberAuthor

@Emyrk Just pinging you in case you didn't see this. Let me know if you're busy, and I can find someone else to review this

Emyrk reacted with thumbs up emoji

@ParkreinerParkreiner requested review fromf0ssel and removed request forEmyrkMarch 18, 2025 13:46
@Parkreiner
Copy link
MemberAuthor

@f0ssel Steven is really heads-down on Mango stuff right now. Would you be able to take over review for this?

Copy link
Contributor

@f0sself0ssel left a comment

Choose a reason for hiding this comment

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

Overall this looks great, the tests are really good coverage and the shared implementation worked out nice.

I suggested some naming changes, mainly because we don't use "callback" very much in Go and like to use "-er" words to describe capabilities.

Parkreiner reacted with heart emoji
@@ -282,7 +285,25 @@ func WebsocketCloseSprintf(format string, vars ...any) string {
return msg
}

func ServerSentEventSender(rw http.ResponseWriter, r *http.Request) (sendEvent func(ctx context.Context, sse codersdk.ServerSentEvent) error, closed chan struct{}, err error) {
type InitializeConnectionCallback func(rw http.ResponseWriter, r *http.Request) (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
typeInitializeConnectionCallbackfunc(rw http.ResponseWriter,r*http.Request) (
typeEventSenderfunc(rw http.ResponseWriter,r*http.Request) (

// open a workspace in multiple tabs, the entire UI can start to lock up.
// WebSockets have no such limitation, no matter what HTTP protocol was used to
// establish the connection.
func OneWayWebSocket(rw http.ResponseWriter, r *http.Request) (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
funcOneWayWebSocket(rw http.ResponseWriter,r*http.Request) (
funcWebSocketEventSender(rw http.ResponseWriter,r*http.Request) (

Comment on lines 439 to 442
type SocketError struct {
Code websocket.StatusCode
Reason string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be declared at the package level.

And just to double check, there isn't already a type like this in websocket is there?

Comment on lines 164 to 171
// Our WebSocket library accepts any arbitrary ResponseWriter at the type level,
// but it must also implement http.Hijack
type mockWsResponseWriter struct {
serverRecorder *httptest.ResponseRecorder
serverConn net.Conn
clientConn net.Conn
serverReadWriter *bufio.ReadWriter
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return w(b)
}

func TestOneWayWebSocket(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because we also touch the SSE Sender, could we include some basic coverage for that if there isn't already?

Parkreiner reacted with thumbs up emoji
@ParkreinerParkreiner requested a review fromf0sselMarch 20, 2025 15:19
@Parkreiner
Copy link
MemberAuthor

@f0ssel Forgot to ping you yesterday, but I applied all your feedback and added tests for the SSE code

Closes#16777## Changes made- Added `OneWayWebSocket` utility class to help enforce one-waycommunication from the server to the client- Updated all client client code to use the new WebSocket-basedendpoints made to replace the current SSE-based endpoints- Updated WebSocket event handlers to be aware of new protocols- Refactored existing `useEffect` calls and removed some synchronizationbugs- Removed dependencies and types for dealing with SSEs- Addressed some minor Biome warnings
@ParkreinerParkreiner merged commit9bc727e intomainMar 28, 2025
35 checks passed
@ParkreinerParkreiner deleted the mes/one-way-ws-01 branchMarch 28, 2025 21:13
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 28, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@f0sself0sself0ssel approved these changes

Assignees

@ParkreinerParkreiner

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add support for One-Way WebSocket communication to backend
2 participants
@Parkreiner@f0ssel

[8]ページ先頭

©2009-2025 Movatter.jp