Skip to content

Conversation

unniznd
Copy link
Contributor

@unniznd unniznd commented Aug 9, 2025

What was wrong?

The multiselect type was inconsistent

How was it fixed?

Set the return type to None and handled the places where the negotiate function is used.

Summary of approach.

To-Do

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

put a cute animal picture link inside the parentheses

@unniznd unniznd changed the title fix: Added multiselect type inconsistency in negotiate method fix: Added multiselect type consistency in negotiate method Aug 9, 2025
@pacrob
Copy link
Member

pacrob commented Aug 12, 2025

Looks good, @unniznd. Please add a newsfragment and it should be good to go.

@unniznd
Copy link
Contributor Author

unniznd commented Aug 12, 2025

@pacrob Added the newsfragment.

@unniznd unniznd closed this Aug 12, 2025
@unniznd unniznd deleted the fix_multiselect_type_inconsistency branch August 12, 2025 16:11
@unniznd
Copy link
Contributor Author

unniznd commented Aug 12, 2025

I will create a new PR. Small mistake, I did rebase.

Copy link
Contributor

@acul71 acul71 left a comment

Choose a reason for hiding this comment

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

Thanks, @unniznd This fix addresses a legitimate type consistency issue and improves error handling throughout the codebase. The implementation is clean, focused, and maintains backward compatibility.

Can you please chore the error messages text and can you add some test to see that the None case is well handled ?
Verify

     # basic_host.py
     raise StreamFailure("failed to negotiate protocol")
     
     # security_multistream.py  
     raise SecurityUpgradeFailure("failed to negotiate the secure protocol")
     
     # muxer_multistream.py
     raise MuxerUpgradeFailure("failed to negotiate the multiplexer protocol")
     ```

@@ -288,6 +288,9 @@ async def _swarm_stream_handler(self, net_stream: INetStream) -> None:
protocol, handler = await self.multiselect.negotiate(
MultiselectCommunicator(net_stream), self.negotiate_timeout
)
if protocol is None:
await net_stream.reset()
raise StreamFailure("No protocol selected")
Copy link
Contributor

Choose a reason for hiding this comment

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

For error messages, can you be more verbose, something like:
raise StreamFailure("Failed to negotiate protocol: no protocol selected")

@@ -114,5 +117,7 @@ async def select_transport(
else:
# Select protocol if non-initiator
protocol, _ = await self.multiselect.negotiate(communicator)
if protocol is None:
raise SecurityUpgradeFailure("No protocol selected")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.
raise SecurityUpgradeFailure("failed to negotiate the secure protocol")

communicator = MultiselectCommunicator(conn)
if conn.is_initiator:
protocol = await self.multiselect_client.select_one_of(
tuple(self.transports.keys()), communicator
)
else:
protocol, _ = await self.multiselect.negotiate(communicator)
if protocol is None:
raise MuxerUpgradeFailure("No protocol selected")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same, somethink like:
aise MuxerUpgradeFailure("failed to negotiate the multiplexer protocol")

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.

6 participants