Skip to content

Commit ecf1d65

Browse files
committed
Stop printing to stderr in lightning-net-tokio for disconnections
It isn't exactly a critical error situation when we disconnect a socket, so we shouldn't be printing to stderr, entirely bypassing user logging, when it happens. We do still print to stderr if we fail to write the first message to the socket, but this should never happen unless the user has a reasonably-configured system with at least one packet in bytes available for the socket buffer.
1 parent 2e02aa7 commit ecf1d65

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,30 +141,23 @@ impl Connection {
141141
PeerDisconnected
142142
}
143143
let disconnect_type = loop {
144-
macro_rules! shutdown_socket {
145-
($err: expr, $need_disconnect: expr) => { {
146-
println!("Disconnecting peer due to {}!", $err);
147-
break $need_disconnect;
148-
} }
149-
}
150-
151144
let read_paused = {
152145
let us_lock = us.lock().unwrap();
153146
if us_lock.rl_requested_disconnect {
154-
shutdown_socket!("disconnect_socket() call from RL", Disconnect::CloseConnection);
147+
break Disconnect::CloseConnection;
155148
}
156149
us_lock.read_paused
157150
};
158151
tokio::select! {
159152
v = write_avail_receiver.recv() => {
160153
assert!(v.is_some()); // We can't have dropped the sending end, its in the us Arc!
161-
if let Err(e) = peer_manager.write_buffer_space_avail(&mut our_descriptor) {
162-
shutdown_socket!(e, Disconnect::CloseConnection);
154+
if let Err(_) = peer_manager.write_buffer_space_avail(&mut our_descriptor) {
155+
break Disconnect::CloseConnection;
163156
}
164157
},
165158
_ = read_wake_receiver.recv() => {},
166159
read = reader.read(&mut buf), if !read_paused => match read {
167-
Ok(0) => shutdown_socket!("Connection closed", Disconnect::PeerDisconnected),
160+
Ok(0) => break Disconnect::PeerDisconnected,
168161
Ok(len) => {
169162
let read_res = peer_manager.read_event(&mut our_descriptor, &buf[0..len]);
170163
let mut us_lock = us.lock().unwrap();
@@ -174,10 +167,10 @@ impl Connection {
174167
us_lock.read_paused = true;
175168
}
176169
},
177-
Err(e) => shutdown_socket!(e, Disconnect::CloseConnection),
170+
Err(_) => break Disconnect::CloseConnection,
178171
}
179172
},
180-
Err(e) => shutdown_socket!(e, Disconnect::PeerDisconnected),
173+
Err(_) => break Disconnect::PeerDisconnected,
181174
},
182175
}
183176
peer_manager.process_events();

0 commit comments

Comments
 (0)