Poll shutdown timeout in rpc handler (#3153)
## Issue Addressed N/A ## Proposed Changes Previously, we were using `Sleep::is_elapsed()` to check if the shutdown timeout had triggered without polling the sleep. This PR polls the sleep timer.
This commit is contained in:
parent
580d2f7873
commit
db0beb5178
@ -137,7 +137,7 @@ enum HandlerState {
|
|||||||
///
|
///
|
||||||
/// While in this state the handler rejects new requests but tries to finish existing ones.
|
/// While in this state the handler rejects new requests but tries to finish existing ones.
|
||||||
/// Once the timer expires, all messages are killed.
|
/// Once the timer expires, all messages are killed.
|
||||||
ShuttingDown(Box<Sleep>),
|
ShuttingDown(Pin<Box<Sleep>>),
|
||||||
/// The handler is deactivated. A goodbye has been sent and no more messages are sent or
|
/// The handler is deactivated. A goodbye has been sent and no more messages are sent or
|
||||||
/// received.
|
/// received.
|
||||||
Deactivated,
|
Deactivated,
|
||||||
@ -252,7 +252,7 @@ where
|
|||||||
self.dial_queue.push((id, OutboundRequest::Goodbye(reason)));
|
self.dial_queue.push((id, OutboundRequest::Goodbye(reason)));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state = HandlerState::ShuttingDown(Box::new(sleep_until(
|
self.state = HandlerState::ShuttingDown(Box::pin(sleep_until(
|
||||||
TInstant::now() + Duration::from_secs(SHUTDOWN_TIMEOUT_SECS as u64),
|
TInstant::now() + Duration::from_secs(SHUTDOWN_TIMEOUT_SECS as u64),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -539,14 +539,15 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we are shutting down, and if the timer ran out
|
// Check if we are shutting down, and if the timer ran out
|
||||||
if let HandlerState::ShuttingDown(delay) = &self.state {
|
if let HandlerState::ShuttingDown(delay) = &mut self.state {
|
||||||
if delay.is_elapsed() {
|
match delay.as_mut().poll(cx) {
|
||||||
self.state = HandlerState::Deactivated;
|
Poll::Ready(_) => {
|
||||||
debug!(self.log, "Handler deactivated");
|
self.state = HandlerState::Deactivated;
|
||||||
return Poll::Ready(ConnectionHandlerEvent::Close(RPCError::InternalError(
|
debug!(self.log, "Handler deactivated");
|
||||||
"Shutdown timeout",
|
return Poll::Ready(ConnectionHandlerEvent::Close(RPCError::Disconnected));
|
||||||
)));
|
}
|
||||||
}
|
Poll::Pending => {}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// purge expired inbound substreams and send an error
|
// purge expired inbound substreams and send an error
|
||||||
|
Loading…
Reference in New Issue
Block a user