Handle simultaneous RPC negotiation errors (#846)
This commit is contained in:
parent
74c34d1602
commit
26be30bc4c
@ -43,8 +43,8 @@ where
|
|||||||
/// The upgrade for inbound substreams.
|
/// The upgrade for inbound substreams.
|
||||||
listen_protocol: SubstreamProtocol<RPCProtocol>,
|
listen_protocol: SubstreamProtocol<RPCProtocol>,
|
||||||
|
|
||||||
/// If `Some`, something bad happened and we should shut down the handler with an error.
|
/// If something bad happened and we should shut down the handler with an error.
|
||||||
pending_error: Option<(RequestId, ProtocolsHandlerUpgrErr<RPCError>)>,
|
pending_error: Vec<(RequestId, ProtocolsHandlerUpgrErr<RPCError>)>,
|
||||||
|
|
||||||
/// Queue of events to produce in `poll()`.
|
/// Queue of events to produce in `poll()`.
|
||||||
events_out: SmallVec<[RPCEvent; 4]>,
|
events_out: SmallVec<[RPCEvent; 4]>,
|
||||||
@ -196,7 +196,7 @@ where
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
RPCHandler {
|
RPCHandler {
|
||||||
listen_protocol,
|
listen_protocol,
|
||||||
pending_error: None,
|
pending_error: Vec::new(),
|
||||||
events_out: SmallVec::new(),
|
events_out: SmallVec::new(),
|
||||||
dial_queue: SmallVec::new(),
|
dial_queue: SmallVec::new(),
|
||||||
dial_negotiated: 0,
|
dial_negotiated: 0,
|
||||||
@ -425,11 +425,7 @@ where
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if self.pending_error.is_none() {
|
self.pending_error.push((request_id, error));
|
||||||
self.pending_error = Some((request_id, error));
|
|
||||||
} else {
|
|
||||||
crit!(self.log, "Couldn't add error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connection_keep_alive(&self) -> KeepAlive {
|
fn connection_keep_alive(&self) -> KeepAlive {
|
||||||
@ -442,7 +438,7 @@ where
|
|||||||
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
|
||||||
Self::Error,
|
Self::Error,
|
||||||
> {
|
> {
|
||||||
if let Some((request_id, err)) = self.pending_error.take() {
|
if let Some((request_id, err)) = self.pending_error.pop() {
|
||||||
// Returning an error here will result in dropping the peer.
|
// Returning an error here will result in dropping the peer.
|
||||||
match err {
|
match err {
|
||||||
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(
|
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(
|
||||||
@ -598,6 +594,14 @@ where
|
|||||||
}
|
}
|
||||||
self.queued_outbound_items.remove(&request_id);
|
self.queued_outbound_items.remove(&request_id);
|
||||||
entry.remove();
|
entry.remove();
|
||||||
|
|
||||||
|
if self.outbound_substreams.is_empty()
|
||||||
|
&& self.inbound_substreams.is_empty()
|
||||||
|
{
|
||||||
|
self.keep_alive = KeepAlive::Until(
|
||||||
|
Instant::now() + self.inactive_timeout,
|
||||||
|
);
|
||||||
|
}
|
||||||
} // drop the stream
|
} // drop the stream
|
||||||
Ok(Async::NotReady) => {
|
Ok(Async::NotReady) => {
|
||||||
entry.get_mut().0 =
|
entry.get_mut().0 =
|
||||||
@ -703,6 +707,13 @@ where
|
|||||||
let delay_key = &entry.get().1;
|
let delay_key = &entry.get().1;
|
||||||
self.outbound_substreams_delay.remove(delay_key);
|
self.outbound_substreams_delay.remove(delay_key);
|
||||||
entry.remove_entry();
|
entry.remove_entry();
|
||||||
|
|
||||||
|
if self.outbound_substreams.is_empty()
|
||||||
|
&& self.inbound_substreams.is_empty()
|
||||||
|
{
|
||||||
|
self.keep_alive =
|
||||||
|
KeepAlive::Until(Instant::now() + self.inactive_timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(Async::NotReady) => {
|
Ok(Async::NotReady) => {
|
||||||
entry.get_mut().0 = OutboundSubstreamState::Closing(substream);
|
entry.get_mut().0 = OutboundSubstreamState::Closing(substream);
|
||||||
|
Loading…
Reference in New Issue
Block a user