Bug 35004 - 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
Summary: Filename returned by LocalEndpoint of UnixListener has null characters append...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.POSIX ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-16 22:22 UTC by David Lechner
Modified: 2016-03-02 16:14 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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!