DnsServer: Delete stale Unix socket files before binding to prevent 'address already in use' errors on restart#2024
Conversation
When the DNS server is restarted, Unix domain socket files from the previous run persist on disk. Kestrel's ListenUnixSocket() then fails: System.IO.IOException: Failed to bind to address http://unix:<path>: address already in use. ---> System.Net.Sockets.SocketException (48): Address already in use Delete the socket file before calling ListenUnixSocket() so that a stale file from a previous run does not prevent binding. DirectoryNotFoundException is silently ignored since it means the parent directory does not exist yet. Also clean up socket files in StopWebServiceAsync() and StopDoHAsync() after disposing the Kestrel host, as defense-in-depth for clean shutdowns.
16d4995 to
cbb8180
Compare
|
Thanks for the PR. In my tests on both Linux and Windows, the socket file that gets created by Kestrel server gets removed too when the server stops. So not sure how you see the stale file there. Do you have any steps to reproduce this? |
|
It happened to me every time I run |
|
Always healthy to clean up such files before use since only a clean shutdown will properly remove them by itself. If you had a crash or the host (when runned as container) suddently pulled the rug under the application stale files will remain and hinder a proper restart. |
When the DNS server is restarted, the Unix domain socket files from the previous run persist on disk. Kestrel's
ListenUnixSocket()then fails with:This PR deletes the socket file before calling
ListenUnixSocket()so that a stale file from a previous run does not prevent binding.DirectoryNotFoundExceptionis silently ignored since it means the parent directory does not exist yet, andListenUnixSocketwill fail with a clearer error in that case.Affected:
DnsWebService.csDnsServer.cs