[GH-ISSUE #2169] Handle sockets that have been shut down #909

Closed
opened 2026-03-16 00:50:34 +03:00 by kerem · 5 comments
Owner

Originally created by @dlon on GitHub (Mar 9, 2024).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2169

Describe the bug
This error is logged indefinitely after a socket used by a ServerFuture has been shut down: [WARN] error receiving message on udp_socket: Socket is not connected (os error 57).

To Reproduce
Create a new ServerFuture and register a UDP socket using ServerFuture::register_listener. Call pid_shutdown_sockets() to shut down all sockets owned by the server process.

Expected behavior
The server should stop trying to receive data and return an error. Alternatively, the socket should be replaced.

System:

  • OS: macOS
  • rustc version: any

Version:
Crate: server
Version: 0.23.0

Originally created by @dlon on GitHub (Mar 9, 2024). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2169 **Describe the bug** This error is logged indefinitely after a socket used by a `ServerFuture` has been shut down: `[WARN] error receiving message on udp_socket: Socket is not connected (os error 57)`. **To Reproduce** Create a new `ServerFuture` and register a UDP socket using `ServerFuture::register_listener`. Call `pid_shutdown_sockets()` to shut down all sockets owned by the server process. **Expected behavior** The server should stop trying to receive data and return an error. Alternatively, the socket should be replaced. **System:** - OS: macOS - rustc version: any **Version:** Crate: server Version: 0.23.0
kerem closed this issue 2026-03-16 00:50:39 +03:00
Author
Owner

@djc commented on GitHub (Mar 9, 2024):

Why are closing all of the process sockets like that? What is the purpose of doing so?

<!-- gh-comment-id:1986823300 --> @djc commented on GitHub (Mar 9, 2024): Why are closing all of the process sockets like that? What is the purpose of doing so?
Author
Owner

@dlon commented on GitHub (Mar 9, 2024):

I've seen sockets being closed/shutdown randomly on a few machines, but I can't tell you why. It might be something that the OS is doing. Regardless, it probably makes no sense to continue to receive/send on them, right?

<!-- gh-comment-id:1986829081 --> @dlon commented on GitHub (Mar 9, 2024): I've seen sockets being closed/shutdown randomly on a few machines, but I can't tell you why. It might be something that the OS is doing. Regardless, it probably makes no sense to continue to receive/send on them, right?
Author
Owner

@bluejekyll commented on GitHub (Mar 9, 2024):

Seems like we should be treating this error differently, but, if the server socket is closing, that would imply the server can no longer be used. It would need to reopen the Socket. What is closing the socket?

To be clear, the socket registered as part of "register_listener" should be live as long as the server itself and never be closed until the server is shutdown.

<!-- gh-comment-id:1986970064 --> @bluejekyll commented on GitHub (Mar 9, 2024): Seems like we should be treating this error differently, but, if the server socket is closing, that would imply the server can no longer be used. It would need to reopen the Socket. What is closing the socket? To be clear, the socket registered as part of "register_listener" should be live as long as the server itself and never be closed until the server is shutdown.
Author
Owner

@dlon commented on GitHub (Mar 11, 2024):

Would it make sense to simply break in the case where ENOTCONN is returned here? (This probably needs to be handled for the non-UDP cases as well.)

I suspect that this issue might occur when the process is suspended under some circumstances. Can't tell you what they are since I haven't been able to reproduce this myself, so I'm just speculating.

Arguably, this case should be handled regardless, since any process (running as root) can call pid_shutdown_sockets to close the sockets. There's no way to gracefully handle this at the moment.

<!-- gh-comment-id:1988375777 --> @dlon commented on GitHub (Mar 11, 2024): Would it make sense to simply break in the case where `ENOTCONN` is returned [here](https://github.com/hickory-dns/hickory-dns/blob/main/crates/server/src/server/server_future.rs#L96)? (This probably needs to be handled for the non-UDP cases as well.) I suspect that this issue might occur when the process is suspended under some circumstances. Can't tell you what they are since I haven't been able to reproduce this myself, so I'm just speculating. Arguably, this case should be handled regardless, since any process (running as root) *can* call `pid_shutdown_sockets` to close the sockets. There's no way to gracefully handle this at the moment.
Author
Owner

@djc commented on GitHub (Mar 11, 2024):

Yes, breaking out of the loop for that scenario seems reasonable. Would you be able to send a PR for that?

<!-- gh-comment-id:1988389173 --> @djc commented on GitHub (Mar 11, 2024): Yes, breaking out of the loop for that scenario seems reasonable. Would you be able to send a PR for that?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#909
No description provided.