Skip to content

Conversation

@andrewryno
Copy link
Member

Basing this off the other PR so I can easily use this commit in my internal use of the library with these two fixes.

This race is a bit simpler than the other one. When calling Disconnect() we set a.agentSession to nil. But we also need to pass that value into the emitted event for an agent disconnect.

This fixes the race by just referencing the actual object in memory instead of the field on the agent. Since the only mutation we do to the agentSession is adding the warnings from the initial connection anyway, this seemed reasonable enough. Plus, if we were to just wrap the a.agentSession usage in the mutex in the event callback, it would still race and potentially be nil depending on when the event gets emitted. This way, the session is always there.

@andrewryno andrewryno requested review from bmpngrok and euank November 11, 2025 23:24
Copy link
Contributor

@bmpngrok bmpngrok left a comment

Choose a reason for hiding this comment

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

Oof, good catch! This one may have more code, but it's a lot easier to work through why this works and what you're fixing.

Base automatically changed from ryno/fix-race-closing-muxado-streams to main November 14, 2025 18:05
@andrewryno andrewryno force-pushed the ryno/fix-race-disconnect branch from b635daf to 5a5159c Compare November 14, 2025 18:14
@andrewryno andrewryno merged commit 0a35072 into main Nov 14, 2025
2 checks passed
@andrewryno andrewryno deleted the ryno/fix-race-disconnect branch November 14, 2025 18:36
@jonstacks jonstacks mentioned this pull request Dec 5, 2025
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.

4 participants