Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

WebListener RC2: 503 Service Unavailable when hosted in Azure Service Fabric #749

Closed
alecor191 opened this issue May 16, 2016 · 15 comments
Closed

Comments

@alecor191
Copy link

I'm having an issue when using WebListener RC2 together with Azure Service Fabric: I have a very simple ASP.NET Core RC2 app that works fine when hosted using WebListener as standalone app.

However, as soon as I host this app in Azure Service Fabric (repro both on local cluster as well as Azure-hosted cluster), the following happens:

  • The app starts up without issues (i.e. webHost.Run() doesn't throw any exception and blocks the thread - expected)

  • As soon as a request is sent to the app, 503 Service Unavailable is returned (expected would be a 200).

  • I took http.sys logs, but all I see there is that it returns a 503, no indication about what the reason could be.

  • I looked at the logs produced by the WebListener, but there are also no error entries; it just shows that it started up successfully:

    Microsoft.AspNetCore.Hosting.Internal.WebHost: Debug: Hosting starting
    Microsoft.Net.Http.Server.WebListener: Information: Start
    Microsoft.Net.Http.Server.WebListener: Information: Listening on prefix: http://localhost:8082/aspnetcorerc2/
    Microsoft.AspNetCore.Hosting.Internal.WebHost: Debug: Hosting started
    
  • If I just replace .UseWebListener() with .UseKestrel() it works fine on both local cluster as well as Azure-hosted cluster.

Here the code that shows how I host the ASP.NET app in Azure Service Fabric:

var webHost = new WebHostBuilder()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseStartup<Startup>()
    .UseWebListener()
    .UseServiceFabricEndpoint("ServiceEndpoint")
    .Build();

ServiceRuntime
    .RegisterServiceAsync(
        "AspCoreRC2StatelessType", 
        serviceContext => new AspCoreRC2StatelessService(serviceContext, webHost))
    .Wait();

webHost.Run();

where UseServiceFabricEndpoint is implemented as follows:

public static IWebHostBuilder UseServiceFabricEndpoint(this IWebHostBuilder webHostBuilder, string endpointName)
{
    var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(endpointName);

    string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}/aspnetcorerc2/";

    webHostBuilder.UseUrls(serverUrl);

    return webHostBuilder;
}

I'm using Microsoft.AspNetCore.Server.WebListener/0.1.0-rc2-20901

BTW the reason I'm using WebListener instead of Kestrel is that I have multiple Service Fabric-hosted apps that all listen on the same port (but different paths). But for troubleshooting I made sure that only the service described above listens on the configured port.

Any idea what I could do to further troubleshoot the root cause of that 503 error?

@Tratcher
Copy link
Member

WebListener strictly enforces the host name match. You registered it on localhost. What host name are you using to contact it?

@alecor191
Copy link
Author

I tried both http://localhost:8082/aspnetcorerc2/ and http://<mylocalmachinename>:8082/aspnetcorerc2/. Neither worked.

When running the app using WebListener and dotnet run I can connect using http://localhost:8082/aspnetcorerc2/.

One difference that I noticed between running the app using dotnet run and using ASF is that in the latter case it runs as Network Service. Could the issue be related to permissions?

@alecor191
Copy link
Author

I just got it working by having WebListener listen on wildcard host name: http://+:8080/aspnetcorerc2/.

What I don't understand yet is why WebListener listening on http://localhost:8080/aspnetcorerc2/ works fine when launching the selfhost app using dotnet run, but it doesn't when hosted in ASF.

Thanks @Tratcher for your input, as it led me to the working solution.

@Tratcher
Copy link
Member

ASF isn't running on the same machine, it's running in a VM or emulator.

@cwe1ss
Copy link
Contributor

cwe1ss commented May 16, 2016

ASF isn't running on the same machine, it's running in a VM or emulator

If you run the local DEV cluster of ASF, there's no emulator or VM involved. ASF acts like there are multiple nodes but all processes are just regular processes on your machine.

@pharring
Copy link

pharring commented Oct 4, 2016

I ran into the same problem when moving from Kestrel to WebListener because the sample code I used (which came from the Visual Studio template for a new Service Fabric ASP.Net Core app) used
FabricRuntime.GetNodeContext().IPAddressOrFQDN for the host name (in WebHostingService.OpenAsync in program.cs). Replacing that expression with '+' made it work for both localhost (debugging in a SF dev cluster on the same box) and a real SF cluster in Azure.

@vikashsingh009
Copy link

Angular2 Apps getting 503 as main.js not loading

@Tratcher
Copy link
Member

@vikashsingh005 check your address registrations. #749 (comment)

@vikashsingh009
Copy link

vikashsingh009 commented Nov 22, 2016

I have Followed the same Pattern like this

 Task<string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken)
            {
                var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(_endpointName);

                string serverUrl = $"{endpoint.Protocol}://+:{endpoint.Port}/company";
                //  string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}/company";
                 _webHost = new WebHostBuilder().UseWebListener()
                                               .UseContentRoot(Directory.GetCurrentDirectory())
                                               .UseStartup<Startup>()
                                               .UseUrls(serverUrl)
                                               .Build();

                _webHost.Start();

                return Task.FromResult(serverUrl);
            }

But , Angular2
angular2error

@Tratcher
Copy link
Member

I don't see any obvious problems, you'll have to ask Service Fabric for help.

@Tratcher
Copy link
Member

Actually, I see you registered /company, but angualr is requesting /app/main.js. Shouldn't that be /company/app/main.js?

@vikashsingh009
Copy link

yes, after changed /app/main.js to /company/app/main.js in Angular2 Apps ,Now Context Path not working like if i hit on browser https://localhost:9999/company Angular2 Page will load but after that it Redirect back to https://localhost:9999 , my goal is to run 2 Fabric Application Internal using Angular2 on same port like 9999 so that i can access 2 application on context path like

https://localhost:9999/company
https://localhost:9999/management

@Tratcher
Copy link
Member

Context Path? You mean HttpContext.Path? What are you doing with it?

When generating redirect urls remember to include HttpContext.PathBase.

@vikashsingh009
Copy link

Where i will use in service fabric ,i have asp.net core Application

my requirement is based on above Discussion like how to access application on same port like 80 based on Application context path,Can you guide me the Steps or sample on fabric to achieve that

@awcab
Copy link

awcab commented Feb 8, 2017

Same here. Changing to + works fine, but localhost results in a 503.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants