Skip to content

Commit f229b10

Browse files
committed
Handle inbound connection setup errors
Log and skip runtime listener failures instead of panicking when accepting inbound connections or converting accepted sockets. These errors can happen in normal operation, so keeping the node running is safer than treating them as unreachable. Co-Authored-By: HAL 9000
1 parent 423ed51 commit f229b10

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,23 @@ impl Node {
420420
break;
421421
}
422422
res = listener.accept() => {
423-
#[allow(clippy::unwrap_used)]
424-
let tcp_stream = res.unwrap().0;
423+
let tcp_stream = match res {
424+
Ok((tcp_stream, _)) => tcp_stream,
425+
Err(e) => {
426+
log_error!(logger, "Failed to accept inbound connection: {}", e);
427+
continue;
428+
},
429+
};
425430
let peer_mgr = Arc::clone(&peer_mgr);
431+
let logger = Arc::clone(&logger);
426432
runtime.spawn_cancellable_background_task(async move {
427-
#[allow(clippy::unwrap_used)]
428-
let tcp_stream = tcp_stream.into_std().unwrap();
433+
let tcp_stream = match tcp_stream.into_std() {
434+
Ok(tcp_stream) => tcp_stream,
435+
Err(e) => {
436+
log_error!(logger, "Failed to convert inbound connection: {}", e);
437+
return;
438+
},
439+
};
429440
lightning_net_tokio::setup_inbound(
430441
Arc::clone(&peer_mgr),
431442
tcp_stream,

0 commit comments

Comments
 (0)