fixed:Goroutine Leak Resolution in Relay Server - #28
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a goroutine leak in the relay server by ensuring guest connection handlers and guest read pumps don’t block indefinitely when a room is shutting down and its event loop has stopped receiving on unbuffered channels.
Changes:
- Guard
c.room.broadcast <- msginClient.readPump()with aselectthat exits when the room is closed (room.done). - Guard guest registration (
r.register <- client) with aselectthat rejects the join when the room is closed (r.done), instead of blocking forever.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Feedback on Code ChangesBugs and Issues
Security Issues
Performance Bottlenecks
Idiomatic Go Conventions
Robust Error Handling
Suggested Changes
Final ThoughtsThe changes address the goroutine leak issue effectively. However, ensure that the connection is closed properly in all error paths, use descriptive close messages, validate incoming messages, handle errors properly, organize the code for better readability, and add logging for better debugging and monitoring. |
VishalRaut2106
left a comment
There was a problem hiding this comment.
Thanks so much for this PR.
Catching that encryption bypass in the CLI is huge—rejecting unencrypted commands instead of falling back to plain text is definitely the right move
What does this PR do?
Resolves a critical goroutine leak in the relay server (fixes #22).
Specifically, this PR:
r.register <- clientin cmd/server/main.go) inside aselectblock. This prevents guest connection handlers from blocking indefinitely if the host disconnects and the room's event loop has terminated before registration finishes.c.room.broadcast <- msgin cmd/server/main.go) inside a similarselectblock monitoring the room'sdonechannel. This ensures that the guest's read pump goroutine terminates cleanly instead of hanging when a room is destroyed.Type of change
Checklist
go build ./...passes locallygo vet ./...passes locally