6

I have a self-hosted OWIN project that I'm trying to run. It is configured to listen on:

http://localhost:8080

Whenever I try to access that URL I get an HTTP Error 503. The service is unavailable error.

I have run netstat -a -b and made absolutely sure there's no other application running on port 8080.

When I change the configuration to http://+:8080 the project works fine. So the only change is localhost to +.

Now here's the weird things:

  • I made sure all entries (localhost:8080 or +:8080) in the HTTP namespace are identical (See this and this, where "iedereen" is dutch for "everyone" (and, yes, this is only on my test-station)). Relevant output of netsh http show urlacl:

    URL Reservations: 
    
    Reserved URL            : http://+:8080/ 
        User: \Everyone
            Listen: Yes
            Delegate: Yes
            SDDL: D:(A;;GAGXGWGR;;;WD) 
    
    Reserved URL            : http://localhost:8080/ 
        User: \Everyone
            Listen: Yes
            Delegate: Yes
            SDDL: D:(A;;GAGXGWGR;;;WD) 
    
  • I have the same issue on port 8081 or other ports; "+" works, "localhost" doesn't. So to make sure there wasn't something conflicting with 8080 I've tried 8081 (and other ports, and, ofcourse, with the correct urlacl's)

  • When I use +:8080 the application can be reached fine; I get the desired response. So it's not a firewall issue. Nor is it for port 8081 or other ports I've tried. Also, the 503 comes from the application (it is an application error after all, but also: when I stop the application I simply get no response instead of a 503), so, again, no firewall issue.
  • I tried running as administrator to no avail, same for running VS as administrator.
  • localhost:8080 works on a coworker's computer (which is how this came up in the first place)
  • localhost resolves fine to 127.0.0.1 and ::1. No altered hosts file.

I can't seem to debug this issue, I can set a breakpoint in my controller method but it is never reached. The application starts fine.

Ok, to the test-code to reproduce:

using Microsoft.Owin.Hosting;
using Owin;
using System;

namespace TestApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (WebApp.Start<WebAppStartup>("http://localhost:8080"))
            {
                Console.WriteLine("Press [enter] to quit...");
                Console.ReadLine();
            }
        }
    }

    internal class WebAppStartup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                context.Response.ContentType = "text/plain";
                return context.Response.WriteAsync("Hello, world.");
            });
        }
    }
}

Again, the above doesn't work unless I change localhost to +.

My main question is: is there a way I can debug this? I get no exceptions on starting the application but the controller method is never reached (or: in the above code, the "Hello, world" is never returned). I've checked the windows eventlog but nothing there.

Note: My problem is not actually a problem (since I have a 'workaround'); when I simply change the config to use http://+:8080 but at this point it's a matter of principle and I'd like to know why + works and localhost doesn't.

I am mostly interested in how to debug this and what the difference between localhost and + is; how to configure OWIN or where to set a breakpoint to see the request come in or the 503 response being sent out or how to get this logged or...


Edit: I have changed the code to read:

using Microsoft.Owin;
using Microsoft.Owin.Hosting;
using Owin;
using System;
using System.Threading.Tasks;

namespace TestApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (WebApp.Start<WebAppStartup>("http://localhost:8080/"))   // or: http://+:8080/
            {
                Console.WriteLine("Press [enter] to quit...");
                Console.ReadLine();
            }
        }
    }

    internal class WebAppStartup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Use<TestMiddleware>();

            app.Run(context =>
            {
                context.Response.ContentType = "text/plain";
                Console.WriteLine("Sending response");
                return context.Response.WriteAsync("Hello, world.");
            });
        }
    }

    public class TestMiddleware : OwinMiddleware
    {
        public TestMiddleware(OwinMiddleware next) : base(next) { }

        public override async Task Invoke(IOwinContext context)
        {
            Console.WriteLine("Begin Request");
            await Next.Invoke(context);
            Console.WriteLine("End Request");
        }
    }
}

When I run the application with http://+:8080 I see the following appear in my console:

Begin Request
Sending response
End Request

And also "Hello, world" appears in my browser. I can set a breakpoint on the "begin request" line and it gets hit. Then, again, I change to http://localhost:8080 and ... HTTP Error 503. The service is unavailable.. Again. Console shows nothing (besides the obvious "Press [enter] to quit..."), the breakpoint is not hit.

RobIII
  • 8,488
  • 2
  • 43
  • 93
  • Are you running on windows? Maybe your `host` file is "altered". Have you tried pinging `localhost`? – Stefan Dec 07 '18 at 10:50
  • Nope, `ping -4 localhost` results in `127.0.0.1`, `ping localhost` results in `::1` – RobIII Dec 07 '18 at 10:52
  • 1
    Have you tried adding a URLACL rule? Htty.sys tries to reserve the url and it sounds like it cannot do that. e.g. netsh http add urlacl url=http://localhost:8080/ user=Users – Jamie Rees Dec 07 '18 at 10:52
  • @JamieRees See the first bullet point; yes I did. – RobIII Dec 07 '18 at 10:52
  • What happens if you use: `http://::1` or `127.0.0.1`?, (just curious) – Stefan Dec 07 '18 at 10:59
  • 1
    @Stefan `http://127.0.0.1:8080/` works, again, when I use `+:8080`, and `503 Service unavailable` when I use `localhost:8080`. Same for `http://[::1]:8080/`, `localhost` -> `503`, `+` -> No problem. As for running as admin; I _am_ testing as admin and will until I get it to work, to _then_ try doing it as 'normal' user. But thanks for the tip! – RobIII Dec 07 '18 at 11:05
  • Hmm, so `127.0.0.1` works, but `localhost` (which points to `127.0.0.1`) doesn't.... we need a Sherlock here ;-) – Stefan Dec 07 '18 at 11:13
  • @Stefan: To be clear: I'm referring to the application (owin) 'configuration', using `localhost:8080` doesn't work, `+:8080` does. The `http://127.0.0.1:8080/` and `http://[::1]:8080/` is what I entered in the browser. – RobIII Dec 07 '18 at 11:15
  • Is this your exact code? I just tried it and works as expected. using `Microsoft.Owin.Hosting 4.0.0` and `.net 4.6.1`, so if you are using the same, it must be an issue outside of the application. – Stefan Dec 07 '18 at 11:31
  • Does `*:8080` work? If so, it may be that another listener is already handing 8080 which can explain why `*` works but `localhost` doesn't. Have a look at this link and see if this helps: https://stackoverflow.com/questions/4598164/whats-the-difference-between-http-80-and-http-80 – kha Dec 07 '18 at 11:33
  • the only thing different in my case: I don't see `localhost` in my `netsh`, the service is available on localhost though. my `host` file is empty. – Stefan Dec 07 '18 at 11:36
  • @kha `*:8080` same thing: 503 service unavailable. I am getting a stronger and stronger feeling _something_ is running on 8080 but `netstat -a -b` doesn't show anything... – RobIII Dec 07 '18 at 11:45
  • @Stefan Yes, this is my exact code. `Microsoft.Owin.Hosting 4.0.0.`, `.Net framework 4.6.1`. I have (just) tried removing the `localhost:8080` entry from the urlacl's (just for the sake of it) but then I can't even start the application (as expected). Mark my words: It's gonna be something stupid... a real "DUH" moment. I just don't know where to look further... – RobIII Dec 07 '18 at 11:46
  • Just to be sure: what is exxacly in your `host` file and can you temporarily remove all entries? (although, a second thought; this shouldn't matter since localhost is correctly redirected to 127.0.0.1 – Stefan Dec 07 '18 at 12:27
  • @Stefan just a default hosts file. Nothing extra in it. But I'd like to get more productive on this 'issue' and start tracing/debugging instead of looking everywhere and nowhere. Is there a way I can actually 'dig in' and see what's going on? – RobIII Dec 07 '18 at 12:37
  • The 503 is coming from the actual application, 100% sure because, when I stop the application, no response is received at all (makes sense, right?). So there should be some point in the application where I can set a breakpoint, add some code or something to 'hook into' OWIN to troubleshoot further. – RobIII Dec 07 '18 at 12:46
  • Yes, it's generated by the pipeline at some point.... but it seems to be one of the first actions it hits. There are some ways to influence it, but to pinpoint the exact location at this point is a bit difficult. Maybe you can try to implement a logger, maybe that helps to pinpoint the issue. – Stefan Dec 07 '18 at 12:58

0 Answers0