Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing service fabric application fails

I have deployed an application to a 5 node standalone cluster. Deployment succeeded successful. But the application did not start because of some bug in the application. I tried removing the application from the cluster using the Service Fabric Explorer but this fails.

The health State of the application is “Error” and the status is “Deleting” The application has 9 services. 6 services show a Health State “Unknown” with a question mark and a Status “Unknown”. 3 services show a health state “Ok” but with a Status “Deleting”.

I have also tried to remove it using powershell:

Remove-ServiceFabricApplication -ApplicationName fabric:/appname -Force -ForceRemove

The result was an Operation timed out.

I also tried the script below that I found in some other post.

Connect-ServiceFabricCluster -ConnectionEndpoint localhost:19000

$nodes = Get-ServiceFabricNode

foreach($node in $nodes)
{
    $replicas = Get-ServiceFabricDeployedReplica -NodeName $node.NodeName -  ApplicationName "fabric:/MyApp"

    foreach ($replica in $replicas)
    {
        Remove-ServiceFabricReplica -ForceRemove -NodeName $node.NodeName -PartitionId $replica.Partitionid -ReplicaOrInstanceId $replica.ReplicaOrInstanceId
    }
}

Also no result, the script did not find any replica to remove.

At the same time we started removing the application one of the system services also changed state. The fabric:/System/NamingService service shows a “Warning” health state. This is on partition 00000000-0000-0000-0000-000000001002. The primary replica shows:
Unhealthy event: SourceId='System.NamingService', Property='Duration_PrimaryRecovery', HealthState='Warning', ConsiderWarningAsError=false. The PrimaryRecovery started at 2016-10-06 07:55:21.252 is taking longer than 30:00.000.

I also restarted every node (1 at the time) with no result.

How to force to remove the application without recreating the cluster because that is not a option for a production environment.

like image 641
Rob Koenis Avatar asked Oct 06 '16 09:10

Rob Koenis


People also ask

How do you remove a Fabric service?

You can uninstall Microsoft Azure Service Fabric from your computer by using the Add/Remove Program feature in the Window's Control Panel. When you find the program Microsoft Azure Service Fabric, click it, and then do one of the following: Windows Vista/7/8/10: Click Uninstall.

Is service Fabric going away?

Today, we are announcing the retirement of Azure Service Fabric Mesh. We will continue to support existing deployments until April 28th, 2021, however new deployments will no longer be permitted through the Service Fabric Mesh API.

How do I restart an application on Fabric?

What you are looking for is the Restart-ServiceFabricDeployedCodePackage command. The Restart-ServiceFabricDeployedCodePackage cmdlet ends the code package process, which restarts all of the user service replicas hosted in that process.

What is service Fabric application?

Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. Service Fabric also addresses the significant challenges in developing and managing cloud native applications.


1 Answers

Yeah this can happen if you don't allow your code to exit RunAsync or Open/Close of your ICommunicationListener.

Some background:

Your service has a lifecycle that is driven by Service Fabric. A small component in your service - you know it as FabricRuntime - drives this. For stateless service instances, it's a simple open/close lifecycle. For stateful services, it's a bit more complex. A stateful service replica opens and closes, but also changes role, between primary, secondary, and none. Lifecycle changes are initiated by Service Fabric and show up as a method call or cancellation token trigger in your code. For example, when a replica is switch to primary, we call your RunAsync method. When it switches from primary to something else, or needs to shut down, the cancellation token is triggered. Either way, the system waits for you to finish your work.

When you go delete a service, we tell your service to change role and close. If your code doesn't respond, then it will get stuck in that state.

To get out of that state, you can run Remove-ServiceFabricReplica -ForceRemove. This essentially drops the replica from the system - as far Service Fabric is concerned, the replica is gone. But your process is still running. So you have to go in and kill the process too.

like image 90
Vaclav Turecek Avatar answered Oct 17 '22 17:10

Vaclav Turecek