Bug 35004

Summary: Filename returned by LocalEndpoint of UnixListener has null characters appended to the end which causes the socket file to not be deleted when the UnixListener is disposed
Product: [Mono] Class Libraries Reporter: David Lechner <david>
Component: Mono.POSIXAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: alkpli, mono-bugs+mono
Priority: ---    
Version: 4.2.0 (C6)   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description David Lechner 2015-10-16 22:22:17 UTC
Here is an NUnit test case:

using System;
using System.IO;

using NUnit.Framework;
using Mono.Unix;

namespace UnixListenerBug
{
  [TestFixture]
  public class Test
  {
    [Test]
    public void TestCase ()
    {
      var socketFile = Path.GetFullPath ("test.socket");
      if (File.Exists (socketFile)) {
        File.Delete (socketFile);
      }
      Assume.That (!File.Exists (socketFile));
      var listener = new UnixListener (socketFile);
      Assert.That (File.Exists (socketFile));

      // change to false to see that dispose does not delete file
      if (true) {
        listener.Start ();
        listener.Stop ();
        var filenameUsedInDisposeMethod = ((UnixEndPoint)listener.LocalEndpoint).Filename;
        Assert.That (filenameUsedInDisposeMethod, Is.EqualTo (socketFile));
      }

      listener.Dispose ();
      Assert.That (!File.Exists (socketFile));
    }
  }
}



More info:

Rather than saving the UnixEndpoint that was passed to UnixListener.Init() [1], it saves the one that is created by the Socket[2]. The get accessor of LocalEndPont here calls UnixEndPoint.Create() [3], which is where it seems the null characters are coming from.

[1]: https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix/UnixEndPoint.cs#L65
[2]: https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix/UnixListener.cs#L61
[3]: https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix/UnixEndPoint.cs#L65



Environment:

=== MonoDevelop ===

Version 5.10
Installation UUID: f9085896-ca5c-4fa8-9f13-4f18e19b076a
Runtime:
	Mono 4.2.1 (Stable 4.2.1.60/804ddbc Tue Oct  6 14:40:19 UTC 2015) (64-bit)
	GTK+ 2.24.23 (elementary theme)

=== Build Information ===

Build information unavailable

=== Operating System ===

Linux
Linux freyr 3.16.0-50-generic #67~14.04.1-Ubuntu SMP Fri Oct 2 22:07:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Comment 1 David Lechner 2015-10-16 22:31:24 UTC
Made a pull request with a proposed fix: https://github.com/mono/mono/pull/2145
Comment 2 Alexander Köplinger [MSFT] 2016-03-02 16:14:43 UTC
I merged the PR, thank you!