Browse Source

net/acceptor: Gracefully handle rustls error in run_accept_loop

parazyd 2 years ago
parent
commit
9de4a2e74b
1 changed files with 21 additions and 2 deletions
  1. 21 2
      src/net/acceptor.rs

+ 21 - 2
src/net/acceptor.rs

@@ -157,10 +157,10 @@ impl Acceptor {
                         );
                         continue
                     }
-                    _ => {
+                    x => {
                         error!(
                             target: "net::acceptor::run_accept_loop()",
-                            "[P2P] Acceptor failed listening: {}", e,
+                            "[P2P] Acceptor failed listening: {} ({})", e, x,
                         );
                         error!(
                             target: "net::acceptor::run_accept_loop()",
@@ -173,6 +173,25 @@ impl Acceptor {
                 // In case a TLS handshake fails, we'll get this:
                 Err(e) if e.kind() == ErrorKind::UnexpectedEof => continue,
 
+                // Handle ErrorKind::Other
+                Err(e) if e.kind() == ErrorKind::Other => {
+                    if let Some(inner) = e.into_inner() {
+                        if let Some(inner) = inner.downcast_ref::<async_rustls::rustls::Error>() {
+                            error!(
+                                target: "net::acceptor::run_accept_loop()",
+                                "[P2P] rustls listener error: {:?}", inner,
+                            );
+                            continue
+                        }
+
+                        error!(
+                            target: "net::acceptor::run_accept_loop()",
+                            "[P2P] Unhandled ErrorKind::Other error: {:?}", inner,
+                        );
+                        continue
+                    }
+                }
+
                 // Errors we didn't handle above:
                 Err(e) => {
                     error!(