Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: delete unix socket path on Dispose of bound Socket #45537

Closed
tmds opened this issue Dec 3, 2020 · 4 comments · Fixed by #52103
Closed

proposal: delete unix socket path on Dispose of bound Socket #45537

tmds opened this issue Dec 3, 2020 · 4 comments · Fixed by #52103
Labels
area-System.Net.Sockets enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@tmds
Copy link
Member

tmds commented Dec 3, 2020

aspnetcore repo has an open issue about unix socket not getting cleaned up on exit: dotnet/aspnetcore#14134.

The socket path of a unix domain socket acts as the address.
When the Socket gets disposed, we should make the address available by deleting the file.

With the current behavior, this program fails:

using System;
using System.Net.Sockets;

namespace console
{
    class Program
    {
        static void Main(string[] args)
        {
            var endpoint = new UnixDomainSocketEndPoint("/tmp/mysocket");
            var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
            socket.Bind(endpoint);
            socket.Dispose();
            socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
            socket.Bind(endpoint);
        }
    }
}
$ dotnet run
Unhandled exception. System.Net.Sockets.SocketException (98): Address already in use
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:line 5111
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:line 738
   at System.Net.Sockets.Socket.Bind(EndPoint localEP) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:line 703
   at console.Program.Main(String[] args) in /tmp/console/Program.cs:line 15

Deleting the file is a visible change, so we should consider backwards compatibility.

Users are likely to have File.Delete already in their applications. Those calls will no-op (on ENOENT).

@wfurt @antonfirsov @stephentoub @dotnet/ncl what do you think?

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net.Sockets untriaged New issue has not been triaged by the area owner labels Dec 3, 2020
@ghost
Copy link

ghost commented Dec 3, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

aspnetcore repo has an open issue about unix socket not getting cleaned up on exit: dotnet/aspnetcore#14134.

The socket path of a unix domain socket acts as the address.
When the Socket gets disposed, we should make the address available by deleting the file.

With the current behavior, this program fails:

using System;
using System.Net.Sockets;

namespace console
{
    class Program
    {
        static void Main(string[] args)
        {
            var endpoint = new UnixDomainSocketEndPoint("/tmp/mysocket");
            var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
            socket.Bind(endpoint);
            socket.Dispose();
            socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
            socket.Bind(endpoint);
        }
    }
}
$ dotnet run
Unhandled exception. System.Net.Sockets.SocketException (98): Address already in use
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:line 5111
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:line 738
   at System.Net.Sockets.Socket.Bind(EndPoint localEP) in /_/src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs:line 703
   at console.Program.Main(String[] args) in /tmp/console/Program.cs:line 15

Deleting the file is a visible change, so we should consider backwards compatibility.

Users are likely to have File.Delete already in their applications. Those calls will no-op (on ENOENT).

@wfurt @antonfirsov @stephentoub @dotnet/ncl what do you think?

Author: tmds
Assignees: -
Labels:

area-System.Net.Sockets, untriaged

Milestone: -

@karelz
Copy link
Member

karelz commented Dec 3, 2020

Sounds reasonable to me -- @antonfirsov @geoffkizer any thoughts?

@antonfirsov
Copy link
Member

Sounds reasonable to me.

@karelz karelz added enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner labels Dec 8, 2020
@karelz
Copy link
Member

karelz commented Dec 8, 2020

Triage: If there are no compat issue (with code manually deleting the file today), we are fine with this.

@karelz karelz added this to the Future milestone Dec 8, 2020
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 30, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label May 31, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 30, 2021
@karelz karelz modified the milestones: Future, 6.0.0 Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Sockets enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants