Skip to content

Commit

Permalink
Tolerate NOTCONN errors when cleaning up with shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Aug 18, 2023
1 parent 08cce68 commit db35146
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions crates/wasi/src/preview2/host/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,31 @@ impl<T: WasiView> tcp::Host for T {
// doesn't block.
let dropped = table.delete_tcp_socket(this)?;

// On non-Unix platforms, do a `shutdown` to wake up any `poll` calls
// that are waiting.
// If we might have an `event::poll` waiting on the socket, wake it up.
#[cfg(not(unix))]
rustix::net::shutdown(&dropped.inner.tcp_socket, rustix::net::Shutdown::ReadWrite).unwrap();
{
let tcp_state = dropped.tcp_state_read_lock();
match &*tcp_state {
HostTcpState::Default
| HostTcpState::BindStarted
| HostTcpState::Bound
| HostTcpState::ListenStarted
| HostTcpState::ListenReady(_)
| HostTcpState::ConnectReady(_) => {}

HostTcpState::Listening(_)
| HostTcpState::Connecting(_)
| HostTcpState::Connected => {
match rustix::net::shutdown(
&dropped.inner.tcp_socket,
rustix::net::Shutdown::ReadWrite,
) {
Ok(()) | Err(Errno::NOTCONN) => {}
Err(err) => Err(err).unwrap(),
}
}
}
}

drop(dropped);

Expand Down

0 comments on commit db35146

Please sign in to comment.