Skip to content

Commit 1c2db65

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 3cba37d commit 1c2db65

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/lib.rs

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

0 commit comments

Comments
 (0)