Skip to content

Commit a2904e8

Browse files
committed
f tokio fixed bug?
1 parent 50c7811 commit a2904e8

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ fn wake_socket_waker_by_ref(orig_ptr: *const ()) {
235235
// fully write, but we only need to provide a write_event() once. Otherwise, the sending thread
236236
// may have already gone away due to a socket close, in which case there's nothing to wake up
237237
// anyway.
238-
let _ = unsafe { (*descriptor).write_avail.clone() }.try_send(());
238+
let mut us = unsafe { (*descriptor).conn.lock() }.unwrap();
239+
let _ = us.write_avail.try_send(());
239240
}
240241
fn drop_socket_waker(orig_ptr: *const ()) {
241242
let _orig_box = unsafe { Box::from_raw(orig_ptr as *mut SocketDescriptor) };
@@ -249,19 +250,12 @@ fn descriptor_to_waker(descriptor: *const SocketDescriptor) -> task::RawWaker {
249250

250251
pub struct SocketDescriptor {
251252
conn: Arc<Mutex<Connection>>,
252-
// Ideally we'd just lock conn and push to the write_avail there, but sadly tokio calls our
253-
// waker irrespective of available space on the first poll_write call, which would result in a
254-
// deadlock, so instead we keep a copy in each SocketDescriptor.
255-
write_avail: mpsc::Sender<()>,
256253
id: u64,
257254
}
258255
impl SocketDescriptor {
259256
fn new(conn: Arc<Mutex<Connection>>) -> Self {
260-
let (id, write_avail) = {
261-
let us = conn.lock().unwrap();
262-
(us.id, us.write_avail.clone())
263-
};
264-
Self { conn, write_avail, id }
257+
let id = conn.lock().unwrap().id;
258+
Self { conn, id }
265259
}
266260
}
267261
impl peer_handler::SocketDescriptor for SocketDescriptor {
@@ -329,7 +323,6 @@ impl Clone for SocketDescriptor {
329323
fn clone(&self) -> Self {
330324
Self {
331325
conn: Arc::clone(&self.conn),
332-
write_avail: self.write_avail.clone(),
333326
id: self.id,
334327
}
335328
}

0 commit comments

Comments
 (0)