Skip to content

Conversation

@algorandskiy
Copy link
Contributor

Summary

Originally Mesher relied on a supplied context to handle termination so network's context supposed to be canceled first. wsNetwork's meshThreadInner executes tryConnect asynchronously so that calling it directly from Mesher after possible network termination ends up with tryConnect goroutine still running.

Sample failure: https://github.com/algorand/go-algorand/actions/runs/16656257238/job/47141871869?pr=6397

Originally Mesher relied on a supplied context to handle termination
so network's context supposed to be canceled first.
wsNetwork's meshThreadInner executes tryConnect asynchronously
so that calling it directly from Mesher after possible network termination
ends up with tryConnect goroutine still running.
@algorandskiy algorandskiy self-assigned this Aug 5, 2025
@algorandskiy algorandskiy added Bug-Fix p2p Work related to the p2p project labels Aug 5, 2025
cfg.meshThreadInterval = meshThreadInterval
}

ctx, cancel := context.WithCancel(cfg.parentCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious, why make a child context and cancel it in baseMesher.stop() if the parent context will be cancelled by the network upstream? or is the issue that for hybridNetwork there is no WithContext() being passed or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the issue with hybrid is the following (in the original code):

  1. Stoping wsNet and then the mesher
  2. In between wsNet.Stop() and mesher.stop() mesher's goroutine calls directly meshThreadInner that spawns a goroutine for tryConnect
  3. Since wsNet.Stop() has already executed, nothing checks for tryConnect wait group and the goroutine still alive when the main thread exits.

@algorandskiy algorandskiy merged commit 5991e1a into algorand:master Aug 5, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug-Fix p2p Work related to the p2p project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants