Pavel Baykov
Pavel Baykov

Reputation: 51

Diagnose reason of failng Service Fabric application

I have stateless Service Fabric service. My service also has a OWIN Web Api Service Endpoint. If I get any exception or error in service startup I see the same error message for all types or errors and exceptions:

    Error event: SourceId='System.FM', Property='State'.
    Partition is below target replica or instance count.

So it's really hard to get the real problem each time. I tried this one:

    AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
    {

    };

But it didn't help. I tried to wrap all my code in try/catch but the no exception was catched.

Does anyone know how to get the real reason/exception messages/error messages from SF?

Upvotes: 2

Views: 1837

Answers (2)

ToDevAndBeyond
ToDevAndBeyond

Reputation: 1503

I was experiencing the same issue with the same generic error from the Service Fabric explorer. Since I was running locally, I was able to open the diagnostics event window in Visual Studio and that gave me the more detailed error message. If you aren't running locally, you can still debug.

See the following link: https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-debugging-your-application

Upvotes: 0

JoshL
JoshL

Reputation: 1716

You've got two basic options... emit diagnostic info (like errors, application events, etc.) from your code and then capture/query that, or run your app outside Service Fabric and debug the startup issues locally.

In a SF production deployment you'll want to set up diagnostics so that your app can emit Event Tracing for Windows (ETW) events alongside the events emitted by the core Service Fabric runtime:

https://azure.microsoft.com/en-us/documentation/articles/service-fabric-diagnostic-how-to-use-elasticsearch/

It's a fair amount of work but necessary if you intend to have any visibility into what your application is doing in production. It's also something you'd need to do (in some form or another) whether you're running in SF or not.

Since in your case you want to debug a startup issue in your code, and since you've got a stateless service based on OWIN Web API, I'd first try to debug it locally outside of Service Fabric, and see if you can isolate the issue that way. Of course this will only help if you're a) able to run locally and b) if the problem isn't specific to SF integration/startup itself. But the only way to determine that is probably to try to run local, outside of the SF runtime.

Hope that helps... good luck!

Upvotes: 2

Related Questions