Skip to content

Conversation

@GheisMohammadi
Copy link
Collaborator

@GheisMohammadi GheisMohammadi commented May 23, 2025

This PR introduces several improvements to the stream management system, focusing on ensuring correctness and thread safety in scenarios involving stream removal, discovery. One of the key changes is the thread-safe handling of RemovalInfo updates. Previously, there was a risk of concurrent modifications leading to incorrect removal state tracking. By ensuring that access to RemovalInfo is synchronized and consistent, we reduce the chance of re-adding a stream that was just removed or still in cooldown, improving the resilience of the system during peer churn.

Additionally, the discovery process was updated to respect the state of removedStreams. Now, before attempting to add a new stream, the system checks whether it has been recently removed and is still within a cooldown window. This prevents the unnecessary or premature reuse of streams that are not ready to be re-established, preserving system stability and stream lifecycle integrity.

The protocol stream counter (numByProto) is also updated more defensively. Counters are now only incremented or decremented after confirming that the corresponding stream was validly added or removed. This change prevents incorrect metrics or internal misreporting that could arise if the counter is blindly mutated, especially in edge cases involving duplicate or stale stream data.

Finally, the cleanup process was improved by ensuring that removed streams are also deleted from the reserved list. This change prevents memory leaks and dangling stream references, ensuring that once a stream is removed from the system, all internal references are cleaned up consistently.

@Frozen Frozen merged commit 692cfc8 into dev Jun 9, 2025
3 checks passed
@Frozen Frozen deleted the improve/stream_handling_v2 branch June 9, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants