Open dlon opened 8 months ago
If it doesn't already work, then there's a good chance that this is not possible.
But I would be happy to hear from someone who knows more about kqueue.
I would agree that this is not possible.
Kqueue removes the file descriptor from its set when the file descriptor gets closed. As far as I know there is no event that you can register to Kqueue to notify you when a socket descriptor gets closed. Since a call to pid_shutdown_sockets
will close all file descriptors forcibly it will just be removed from the Kqueue set without notifying the tokio::net::TcpListener
.
See Kqueue man for reference.
The reason why a call to std::net::TcpListener::accept
will return an error is that it calls libc::accept
and blocks. When the FD gets closed this syscall returns with an error.
Version 1.36.0
Platform Darwin Kernel Version 23.2.0 macOS 14.2.1
Description
TcpListener::accept()
doesn't fail when the socket is forcibly closed, whereasstd::net::TcpListener
does.macOS has a syscall
pid_shutdown_sockets
which can close sockets for arbitrary processes. I want to be able to handle this situation.Run this code:
Expected:
TcpListener::accept
should return (fail) whenpid_shutdown_sockets
shuts down the socket. This is what occurs usingstd::net::TcpListener
. Instead,accept
never returns.