Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[agent] Fix a goroutine leak that happens when a websocket connection is closed. #143

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

ojarjur
Copy link
Collaborator

@ojarjur ojarjur commented Nov 25, 2024

Fix a bug where the agent would leak goroutines when a websocket connection is closed.

This was caused by the logic that coordinates reading and writing to the websocket connection to be too complicated, and using a channel for communicating when to exit instead of just cancelling the context.

The use of that (unbuffered) channel then caused a leak when two separate goroutines both tried to send a message to the channel, but only one read was ever performed, and as a result the second goroutine would always hang indefinitely.

This leak and the corresponding fix were confirmed using manual testing.

This change also fixes a bad coding pattern where we stored the context in a struct. Instead, we just store the methods from that context that are actually needed.

Fix a bug where the agent would leak goroutines when a websocket connection is closed.

This was caused by the logic that coordinates reading and writing to the websocket connection to be too complicated, and using a channel for communicating when to exit instead of just cancelling the context.

The use of that (unbuffered) channel then caused a leak when two separate goroutines both tried to send a message to the channel, but only one read was ever performed, and as a result the second goroutine would always hang indefinitely.

This leak and the corresponding fix were confirmed using manual testing.
@ojarjur ojarjur merged commit bba95ff into master Nov 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants