mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 19:02:13 +00:00
Fix MultiHandler panicking when empty (#1598)
This commit is contained in:
parent
c76327e6b5
commit
cacd7300de
@ -157,6 +157,12 @@ where
|
|||||||
fn poll(&mut self, cx: &mut Context)
|
fn poll(&mut self, cx: &mut Context)
|
||||||
-> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent, Self::Error>>
|
-> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent, Self::Error>>
|
||||||
{
|
{
|
||||||
|
// Calling `gen_range(0, 0)` (see below) would panic, so we have return early to avoid
|
||||||
|
// that situation.
|
||||||
|
if self.handlers.is_empty() {
|
||||||
|
return Poll::Pending;
|
||||||
|
}
|
||||||
|
|
||||||
// Not always polling handlers in the same order should give anyone the chance to make progress.
|
// Not always polling handlers in the same order should give anyone the chance to make progress.
|
||||||
let pos = rand::thread_rng().gen_range(0, self.handlers.len());
|
let pos = rand::thread_rng().gen_range(0, self.handlers.len());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user