Diagnose common code package errors by using Service Fabric

This article describes what it means for a code package to terminate unexpectedly. It provides insight into possible causes of common error codes, along with troubleshooting steps.

When does a process or container terminate unexpectedly?

When Azure Service Fabric receives a request to start a code package, it begins preparing the environment on the local system according to the options set in the App and Service manifests. These preparations might include reserving network endpoints or resources, configuring firewall rules, or setting up resource governance constraints.

After the environment has been configured properly, Service Fabric tries to bring up the code package. This step is considered successful if the OS or container runtime reports that the process or container has been activated successfully. If activation is unsuccessful, you should see a health message in SFX that resembles the following:

There was an error during CodePackage activation. Service host failed to activate. Error: 0xXXXXXXXX

After the code package has been successfully activated, Service Fabric begins monitoring its lifetime. At this point, a process or container can terminate at any time for a number of reasons. For example, it might have failed to initialize a DLL, or the OS could have run out of desktop heap space. If your code package terminated, you should see the following health message in SFX:

The process/container terminated with exit code: XXXXXXXX. Please look at your application logs/dump or debug your code package for more details. For information about common termination errors, please visit https://aka.ms/service-fabric-termination-errors

The exit code in this health message is the only clue that the process or container provides about why it terminated. It could be generated by any level of the stack. For example, this exit code might be related to an OS error or a .NET issue, or it might have been raised by your code. Use this article as a starting point for diagnosing the source of termination exit codes and possible solutions. But keep in mind that these are general solutions to common scenarios and might not apply to the error you're seeing.

How can I tell if Service Fabric terminated my code package?

Service Fabric might be responsible for terminating your code package for a variety of reasons. For example, it might decide to place the code package on another node for load-balancing purposes. You can verify that Service Fabric terminated your code package if you see any of the exit codes in the following table.

Note

If your process or container terminates with an exit code other than the codes in the following table, Service Fabric is not responsible for terminating it.

Exit code Description
7147 Indicates that Service Fabric gracefully shut down the process or container by sending it a Ctrl+C signal.
7148 Indicates that Service Fabric terminated the process or container. Sometimes, this error code indicates that the process or container didn't respond in a timely manner after sending a Ctrl+C signal, and it had to be terminated.

Other common error codes and their potential fixes

Exit code Hexadecimal value Short description Root cause Potential fix
3221225794 0xc0000142 STATUS_DLL_INIT_FAILED This error sometimes means that the machine has run out of desktop heap space. This cause is especially likely if you have numerous processes that belong to your application running on the node. If your program wasn't built to respond to Ctrl+C signals, you can enable the EnableActivateNoWindow setting in the Cluster manifest. Enabling this setting means your code package will run without a GUI window and won't receive Ctrl+C signals. This action also reduces the amount of desktop heap space each process consumes. If your code package needs to receive Ctrl+C signals, you can increase the size of your node's desktop heap.
3762504530 0xe0434352 N/A This value represents the error code for an unhandled exception from managed code (that is, .NET). This exit code indicates that your application raised an exception that remains unhandled and which terminated the process. As the first step in determining what triggered this error, debug your application's logs and dump files.

Next steps