Skip to content

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

Closed

Description

@tmds

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?

Activity

  1. karelz commented on Dec 3, 2020

    @karelz
    Member

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

  2. antonfirsov commented on Dec 3, 2020

    @antonfirsov
    Contributor

    Sounds reasonable to me.

  3. added
    enhancementProduct code improvement that does NOT require public API changes/additions
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Dec 8, 2020
  4. karelz commented on Dec 8, 2020

    @karelz
    Member

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

  5. added this to the Future milestone on Dec 8, 2020
  6. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Apr 30, 2021
  7. added a commit that references this issue on May 31, 2021
    d3ed5a9
  8. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on May 31, 2021
  9. ghost locked as resolved and limited conversation to collaborators on Jun 30, 2021
  10. modified the milestones: Future, 6.0.0 on Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.SocketsenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions