Skip to content

Commit

Permalink
avoid potential panics on shutdown
Browse files Browse the repository at this point in the history
Fixes amqp-rs#358

Signed-off-by: Marc-Antoine Perennou <[email protected]>
  • Loading branch information
Keruspe committed Jan 30, 2022
1 parent 636a903 commit 6d6c27b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions async-lapin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ async fn heartbeat(heartbeat: Heartbeat) {
}

async fn poll_read(socket: Arc<Async<TcpStreamWrapper>>, socket_state: SocketStateHandle) {
socket.readable().await.unwrap();
socket_state.send(SocketEvent::Readable);
if socket.readable().await.is_ok() {
socket_state.send(SocketEvent::Readable);
}
}

async fn poll_write(socket: Arc<Async<TcpStreamWrapper>>, socket_state: SocketStateHandle) {
socket.writable().await.unwrap();
socket_state.send(SocketEvent::Writable);
if socket.writable().await.is_ok() {
socket_state.send(SocketEvent::Writable);
}
}
12 changes: 8 additions & 4 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,16 @@ mod unix {
}

async fn poll_read(socket: Arc<AsyncFd<TcpStreamWrapper>>, socket_state: SocketStateHandle) {
socket.readable().await.unwrap().clear_ready();
socket_state.send(SocketEvent::Readable);
if let Ok(mut events) = socket.readable().await {
events.clear_ready();
socket_state.send(SocketEvent::Readable);
}
}

async fn poll_write(socket: Arc<AsyncFd<TcpStreamWrapper>>, socket_state: SocketStateHandle) {
socket.writable().await.unwrap().clear_ready();
socket_state.send(SocketEvent::Writable);
if let Ok(mut events) = socket.writable().await {
events.clear_ready();
socket_state.send(SocketEvent::Writable);
}
}
}

0 comments on commit 6d6c27b

Please sign in to comment.