Skip to content

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
@ojarjur ojarjur deleted the ojarjur/agent-websockets-leak branch March 10, 2025 14:46
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