Skip to content

Commit acc1cdc

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 e972486 commit acc1cdc

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
@@ -421,12 +421,23 @@ impl Node {
421421
break;
422422
}
423423
res = listener.accept() => {
424-
#[allow(clippy::unwrap_used)]
425-
let tcp_stream = res.unwrap().0;
424+
let tcp_stream = match res {
425+
Ok((tcp_stream, _)) => tcp_stream,
426+
Err(e) => {
427+
log_error!(logger, "Failed to accept inbound connection: {}", e);
428+
continue;
429+
},
430+
};
426431
let peer_mgr = Arc::clone(&peer_mgr);
432+
let logger = Arc::clone(&logger);
427433
runtime.spawn_cancellable_background_task(async move {
428-
#[allow(clippy::unwrap_used)]
429-
let tcp_stream = tcp_stream.into_std().unwrap();
434+
let tcp_stream = match tcp_stream.into_std() {
435+
Ok(tcp_stream) => tcp_stream,
436+
Err(e) => {
437+
log_error!(logger, "Failed to convert inbound connection: {}", e);
438+
return;
439+
},
440+
};
430441
lightning_net_tokio::setup_inbound(
431442
Arc::clone(&peer_mgr),
432443
tcp_stream,

0 commit comments

Comments
 (0)