feat: add scheduler support for timeout management in Multiselect#312
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds scheduler support for timeout management in the Multiselect module to ensure that protocol negotiations do not hang indefinitely.
- Introduces a timeout for negotiations in MultiselectInstance using a scheduler.
- Updates the Multiselect and header files to pass and store the scheduler pointer.
- Adds an onTimeout handler that closes the connection upon timeout.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/protocol_muxer/multiselect/multiselect_instance.cpp | Adds scheduler-based timeout scheduling and corresponding cancellation in close(). |
| src/protocol_muxer/multiselect.cpp | Passes scheduler pointer when creating a new MultiselectInstance. |
| include/libp2p/protocol_muxer/multiselect/multiselect_instance.hpp | Declares the scheduler member, timeout handle, and onTimeout() method. |
| include/libp2p/protocol_muxer/multiselect.hpp | Introduces the scheduler pointer as part of the Multiselect class. |
turuslan
reviewed
Jun 11, 2025
| closed_ = true; | ||
|
|
||
| // Cancel timeout if it's still active | ||
| timeout_handle_.reset(); |
Contributor
There was a problem hiding this comment.
Should we reset() connection/stream, to cancel pending read/write?
Contributor
Author
There was a problem hiding this comment.
I think it will be automatically reset, once we erase this active instance:
cpp-libp2p/src/protocol_muxer/multiselect.cpp
Lines 56 to 64 in 4bd3a78
It might live a little longer in the cache, but eventually a new connection will replace the one from the instance
turuslan
approved these changes
Jun 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds timeout on MultiselectInstance's selectOneOf