Force delete application while the Application/Service stuck in deleting state

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Few days back i was working on scenario where I was unable to delete the application and service from Azure Service fabric explorer and PowerShell. By looking at the application state in Service Fabric Explorer the application was in deleting state.

 

Executing the PowerShell command left out with the following error:

Remove-ServiceFabricApplication -ApplicationName fabric:/Voting -Force -TimeoutSec 350

Remove-ServiceFabricApplication : Operation timed out.

At line:1 char:1

+ Remove-ServiceFabricApplication -ApplicationName fabric:/Voting -Forc ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationTimeout: (Microsoft.Servi...usterConnection:ClusterConnection) [Remove-ServiceFabricApplication], TimeoutException

    + FullyQualifiedErrorId : RemoveApplicationInstanceErrorId,Microsoft.ServiceFabric.Powershell.RemoveApplication

 

At this scenario, there are PowerShell cmdlet switches which play a vital role and can help to mitigate the issue. I have tried using -ForceRemove switch. The following cmdlet helps me to delete all application that are distributed across multiple nodes.

 

$ClusterName= "clustername.cluster_region.cloudapp.azure.com:19000"

$Certthumprint = "{replace_with_ClusterThumprint}"

Connect-ServiceFabricCluster -ConnectionEndpoint $ClusterName -KeepAliveIntervalInSec 10 `

     -X509Credential `

     -ServerCertThumbprint $Certthumprint  `

     -FindType FindByThumbprint `

     -FindValue $Certthumprint `

     -StoreLocation CurrentUser `

     -StoreName My

$ApplicationName = "fabric:/voting"

 

foreach($node in Get-ServiceFabricNode)

{  

 [void](Get-ServiceFabricDeployedReplica -NodeName $node.NodeName -ApplicationName $ApplicationName | Remove-ServiceFabricReplica -NodeName $node.NodeName -ForceRemove)

}

Remove-ServiceFabricApplication -ApplicationName $ApplicationName -Force

 

There might be situation where -Force switch could also fail. In that scenario try with

1) Move the Cluster Manager primary to another node and try to remove the app again:

  1. a) Move-ServiceFabricPrimaryReplica -PartitionId [Cluster Manager System Service Partition Id] -ServiceName fabric:/System/ClusterManagerService
  2. b) Remove-ServiceFabricApplication -ApplicationName fabric:/voting -Force -ForceRemove

                               

2) If it still doesn't work due to stuck services or PLB affinity, try to move the primary for each partition of NamingService and try again.

There might also a scenario that the issue is happening with only one service distributed in multiple nodes instead of the whole application. Then use the below script which is like the one for application but with a little change which will only delete a specific Service.

 

$ClusterName= "clustername.cluster_region.cloudapp.azure.com:19000"

$Certthumprint = "{replace_with_ClusterThumprint}"

Connect-ServiceFabricCluster -ConnectionEndpoint $ClusterName -KeepAliveIntervalInSec 10 `

     -X509Credential `

     -ServerCertThumbprint $Certthumprint  `

     -FindType FindByThumbprint `

     -FindValue $Certthumprint `

     -StoreLocation CurrentUser `

     -StoreName My

$ApplicationName = "fabric:/voting"

$ServiceName = "fabric:/Voting/FEService"

 

foreach($node in Get-ServiceFabricNode)

{  

 [void](Get-ServiceFabricDeployedReplica -NodeName $node.NodeName -ApplicationName $ApplicationName | Where-Object {$_.ServiceName -match $ServiceName} | Remove-ServiceFabricReplica -NodeName $node.NodeName -ForceRemove)

}

 

Remove-ServiceFabricService -ServiceName $ServiceName -Force  

 

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.