Stop panicking when the connection error slot is not set (#4770)

This commit is contained in:
teor 2022-07-12 10:16:19 +10:00 committed by GitHub
parent c4f89ed2e1
commit f7889acaf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -19,7 +19,7 @@ use tokio::{sync::broadcast, task::JoinHandle};
use tower::Service; use tower::Service;
use crate::{ use crate::{
peer::error::AlreadyErrored, peer::error::{AlreadyErrored, ErrorSlot, PeerError, SharedPeerError},
peer_set::InventoryChange, peer_set::InventoryChange,
protocol::{ protocol::{
external::{types::Version, InventoryHash}, external::{types::Version, InventoryHash},
@ -27,8 +27,6 @@ use crate::{
}, },
}; };
use super::{ErrorSlot, PeerError, SharedPeerError};
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
pub mod tests; pub mod tests;
@ -491,11 +489,12 @@ impl Client {
/// Poll for space in the shared request sender channel. /// Poll for space in the shared request sender channel.
fn poll_request(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), SharedPeerError>> { fn poll_request(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), SharedPeerError>> {
if ready!(self.server_tx.poll_ready(cx)).is_err() { let server_result = ready!(self.server_tx.poll_ready(cx));
if server_result.is_err() {
Poll::Ready(Err(self Poll::Ready(Err(self
.error_slot .error_slot
.try_get_error() .try_get_error()
.expect("failed servers must set their error slot"))) .unwrap_or_else(|| PeerError::ConnectionTaskExited.into())))
} else if let Some(error) = self.error_slot.try_get_error() { } else if let Some(error) = self.error_slot.try_get_error() {
Poll::Ready(Err(error)) Poll::Ready(Err(error))
} else { } else {
@ -569,13 +568,15 @@ impl Service<Request> for Client {
}) { }) {
Err(e) => { Err(e) => {
if e.is_disconnected() { if e.is_disconnected() {
let ClientRequest { tx, .. } = e.into_inner(); let peer_error = self
let _ = tx.send(Err(PeerError::ConnectionClosed.into()));
future::ready(Err(self
.error_slot .error_slot
.try_get_error() .try_get_error()
.expect("failed servers must set their error slot"))) .unwrap_or_else(|| PeerError::ConnectionTaskExited.into());
.boxed()
let ClientRequest { tx, .. } = e.into_inner();
let _ = tx.send(Err(peer_error.clone()));
future::ready(Err(peer_error)).boxed()
} else { } else {
// sending fails when there's not enough // sending fails when there's not enough
// channel space, but we called poll_ready // channel space, but we called poll_ready