Search Unity

HttpListener ignores port on some windows platform(s)

Discussion in 'Windows' started by jerome-lacoste, Aug 23, 2019.

  1. jerome-lacoste

    jerome-lacoste

    Joined:
    Jan 7, 2012
    Posts:
    139
    Hello,

    we distribute a cross-plaform (Windows, Mac, Linux) application that opens a port to accept incoming web requests in order to receive OAuth auth browser callback.s. The code does something like:

    listener = new HttpListener();
    listener.Prefixes.Add("http://127.0.0.1:12345"); // hardcoded uri for the example.
    listener.Start();

    Unfortunately on at least one server, the port number specified in the uri appears to be ignored and the effective opened port seems random. See the difference between the log file and the netstat output on the right.

    image(1).png

    The affectetd server runs Windows Server 2012 R2.

    We tried DotNet 3.5 or 4.6, x86 or 64 targets. Using Unity 2017.4.29f1.

    To me this sounds like a bug in Mono. I had a quick look at the HttpListener mono code and it looks rather straightforward. So we've filled a bug report yesterday.

    We're considering adding custom code to detect the effective port number.

    Has anyone encountered something similar? Any idea for a work-around?

    Update: sample available here https://github.com/DragonBox/unity_httplistenerport_bug

    Thanks
     
    Last edited: Aug 23, 2019
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,436
    Do you know if this reproduces with the new Mono runtime?
     
  3. jerome-lacoste

    jerome-lacoste

    Joined:
    Jan 7, 2012
    Posts:
    139
    @Tautvydas-Zilys if you mean the 4.6 equivalent present in Unity 2017.4.29f1, we tried and it still fails. (That's what I tried saying when I wrote "We tried DotNet 3.5 or 4.6, x86 or 64 targets. Using Unity 2017.4.29f1.")

    If you want me to try to test something else, let us know. In the mean time we wrote an open port detection work-around... The case is #1178646
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,436
    Thanks for the report!
     
  5. jerome-lacoste

    jerome-lacoste

    Joined:
    Jan 7, 2012
    Posts:
    139
    Hello @Tautvydas-Zilys, we got told in our bug report that the HttpListener is not part of Unity and our issue was closed.

    As far as we understand, the Windows binary ships with a Mono System.dll containing the HttpListener implementation.

    Could we get the issue resolution re-evaluated? Thanks
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,436
    Looks like the QA you've been talking to was initially mistaken. Once you told him it was part of Unity, he kept trying to reproduce but failed. Looks like he reached out to you again with his results a few hours ago - please keep following up with him so we could better understand the issue.