Skip to content

Commit 153b4cc

Browse files
author
Victor Ermolaev
committed
Gossipsub: remove ConnectionHandlerEvent::Close
1 parent eb5e269 commit 153b4cc

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

protocols/gossipsub/src/handler.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use log::{error, trace, warn};
3737
use smallvec::SmallVec;
3838
use std::{
3939
collections::VecDeque,
40-
io,
4140
pin::Pin,
4241
task::{Context, Poll},
4342
time::Duration,
@@ -291,13 +290,16 @@ impl ConnectionHandler for Handler {
291290
> {
292291
// Handle any upgrade errors
293292
if let Some(error) = self.upgrade_errors.pop_front() {
294-
let reported_error = match error {
293+
match error {
295294
// Timeout errors get mapped to NegotiationTimeout and we close the connection.
296295
ConnectionHandlerUpgrErr::Timeout | ConnectionHandlerUpgrErr::Timer => {
297296
Some(HandlerError::NegotiationTimeout)
298297
}
299298
// There was an error post negotiation, close the connection.
300-
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => Some(e),
299+
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => {
300+
self.keep_alive = KeepAlive::No;
301+
log::info!("Gossipsub error: {e}");
302+
}
301303
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(negotiation_error)) => {
302304
match negotiation_error {
303305
NegotiationError::Failed => {
@@ -317,15 +319,14 @@ impl ConnectionHandler for Handler {
317319
}
318320
}
319321
NegotiationError::ProtocolError(e) => {
320-
Some(HandlerError::NegotiationProtocolError(e))
322+
self.keep_alive = KeepAlive::No;
323+
log::info!(
324+
"Gossipsub error: {}",
325+
HandlerError::NegotiationProtocolError(e)
326+
);
321327
}
322328
}
323329
}
324-
};
325-
326-
// If there was a fatal error, close the connection.
327-
if let Some(error) = reported_error {
328-
return Poll::Ready(ConnectionHandlerEvent::Close(error));
329330
}
330331
}
331332

@@ -340,9 +341,8 @@ impl ConnectionHandler for Handler {
340341

341342
if self.inbound_substreams_created > MAX_SUBSTREAM_CREATION {
342343
// Too many inbound substreams have been created, end the connection.
343-
return Poll::Ready(ConnectionHandlerEvent::Close(
344-
HandlerError::MaxInboundSubstreams,
345-
));
344+
self.keep_alive = KeepAlive::No;
345+
log::info!("Gossipsub error: {}", HandlerError::MaxInboundSubstreams);
346346
}
347347

348348
// determine if we need to create the stream
@@ -351,9 +351,8 @@ impl ConnectionHandler for Handler {
351351
&& !self.outbound_substream_establishing
352352
{
353353
if self.outbound_substreams_created >= MAX_SUBSTREAM_CREATION {
354-
return Poll::Ready(ConnectionHandlerEvent::Close(
355-
HandlerError::MaxOutboundSubstreams,
356-
));
354+
self.keep_alive = KeepAlive::No;
355+
log::info!("Gossipsub error: {}", HandlerError::MaxInboundSubstreams);
357356
}
358357
let message = self.send_queue.remove(0);
359358
self.send_queue.shrink_to_fit();
@@ -475,14 +474,14 @@ impl ConnectionHandler for Handler {
475474
Some(OutboundSubstreamState::WaitingOutput(substream));
476475
}
477476
Err(e) => {
478-
error!("Error sending message: {}", e);
479-
return Poll::Ready(ConnectionHandlerEvent::Close(e));
477+
error!("Error sending message: {e}");
478+
break;
480479
}
481480
}
482481
}
483482
Poll::Ready(Err(e)) => {
484-
error!("Outbound substream error while sending output: {:?}", e);
485-
return Poll::Ready(ConnectionHandlerEvent::Close(e));
483+
error!("Outbound substream error while sending output: {e:?}");
484+
break;
486485
}
487486
Poll::Pending => {
488487
self.keep_alive = KeepAlive::Yes;
@@ -504,7 +503,8 @@ impl ConnectionHandler for Handler {
504503
Some(OutboundSubstreamState::WaitingOutput(substream))
505504
}
506505
Poll::Ready(Err(e)) => {
507-
return Poll::Ready(ConnectionHandlerEvent::Close(e))
506+
log::info!("NegotaitedSubstream error: {e}");
507+
break;
508508
}
509509
Poll::Pending => {
510510
self.keep_alive = KeepAlive::Yes;
@@ -525,14 +525,8 @@ impl ConnectionHandler for Handler {
525525
break;
526526
}
527527
Poll::Ready(Err(e)) => {
528-
warn!("Outbound substream error while closing: {:?}", e);
529-
return Poll::Ready(ConnectionHandlerEvent::Close(
530-
io::Error::new(
531-
io::ErrorKind::BrokenPipe,
532-
"Failed to close outbound substream",
533-
)
534-
.into(),
535-
));
528+
warn!("Outbound substream error while closing: {e:?}");
529+
break;
536530
}
537531
Poll::Pending => {
538532
self.keep_alive = KeepAlive::No;

0 commit comments

Comments
 (0)