@@ -37,7 +37,6 @@ use log::{error, trace, warn};
37
37
use smallvec:: SmallVec ;
38
38
use std:: {
39
39
collections:: VecDeque ,
40
- io,
41
40
pin:: Pin ,
42
41
task:: { Context , Poll } ,
43
42
time:: Duration ,
@@ -291,13 +290,16 @@ impl ConnectionHandler for Handler {
291
290
> {
292
291
// Handle any upgrade errors
293
292
if let Some ( error) = self . upgrade_errors . pop_front ( ) {
294
- let reported_error = match error {
293
+ match error {
295
294
// Timeout errors get mapped to NegotiationTimeout and we close the connection.
296
295
ConnectionHandlerUpgrErr :: Timeout | ConnectionHandlerUpgrErr :: Timer => {
297
296
Some ( HandlerError :: NegotiationTimeout )
298
297
}
299
298
// 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
+ }
301
303
ConnectionHandlerUpgrErr :: Upgrade ( UpgradeError :: Select ( negotiation_error) ) => {
302
304
match negotiation_error {
303
305
NegotiationError :: Failed => {
@@ -317,15 +319,14 @@ impl ConnectionHandler for Handler {
317
319
}
318
320
}
319
321
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
+ ) ;
321
327
}
322
328
}
323
329
}
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) ) ;
329
330
}
330
331
}
331
332
@@ -340,9 +341,8 @@ impl ConnectionHandler for Handler {
340
341
341
342
if self . inbound_substreams_created > MAX_SUBSTREAM_CREATION {
342
343
// 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 ) ;
346
346
}
347
347
348
348
// determine if we need to create the stream
@@ -351,9 +351,8 @@ impl ConnectionHandler for Handler {
351
351
&& !self . outbound_substream_establishing
352
352
{
353
353
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 ) ;
357
356
}
358
357
let message = self . send_queue . remove ( 0 ) ;
359
358
self . send_queue . shrink_to_fit ( ) ;
@@ -475,14 +474,14 @@ impl ConnectionHandler for Handler {
475
474
Some ( OutboundSubstreamState :: WaitingOutput ( substream) ) ;
476
475
}
477
476
Err ( e) => {
478
- error ! ( "Error sending message: {}" , e ) ;
479
- return Poll :: Ready ( ConnectionHandlerEvent :: Close ( e ) ) ;
477
+ error ! ( "Error sending message: {e}" ) ;
478
+ break ;
480
479
}
481
480
}
482
481
}
483
482
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 ;
486
485
}
487
486
Poll :: Pending => {
488
487
self . keep_alive = KeepAlive :: Yes ;
@@ -504,7 +503,8 @@ impl ConnectionHandler for Handler {
504
503
Some ( OutboundSubstreamState :: WaitingOutput ( substream) )
505
504
}
506
505
Poll :: Ready ( Err ( e) ) => {
507
- return Poll :: Ready ( ConnectionHandlerEvent :: Close ( e) )
506
+ log:: info!( "NegotaitedSubstream error: {e}" ) ;
507
+ break ;
508
508
}
509
509
Poll :: Pending => {
510
510
self . keep_alive = KeepAlive :: Yes ;
@@ -525,14 +525,8 @@ impl ConnectionHandler for Handler {
525
525
break ;
526
526
}
527
527
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 ;
536
530
}
537
531
Poll :: Pending => {
538
532
self . keep_alive = KeepAlive :: No ;
0 commit comments