%3CLINGO-SUB%20id%3D%22lingo-sub-1303747%22%20slang%3D%22en-US%22%3EForce%20delete%20application%20while%20the%20Application%2FService%20stuck%20in%20deleting%20state%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1303747%22%20slang%3D%22en-US%22%3E%3CP%3EFew%20days%20back%20i%20was%20working%20on%20scenario%20where%20I%20was%20unable%20to%20delete%20the%20application%20and%20service%20from%20Azure%20Service%20fabric%20explorer%20and%20PowerShell.%20By%20looking%20at%20the%20application%20state%20in%20Service%20Fabric%20Explorer%20the%20application%20was%20in%20%3CSTRONG%3E%3CU%3Edeleting%3C%2FU%3E%3C%2FSTRONG%3E%20state.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExecuting%20the%20PowerShell%20command%20left%20out%20with%20the%20following%20error%3A%3C%2FP%3E%0A%3CP%3E%3CEM%3ERemove-ServiceFabricApplication%20-ApplicationName%20fabric%3A%2FVoting%20-Force%20-TimeoutSec%20350%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3ERemove-ServiceFabricApplication%20%3A%20Operation%20timed%20out.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EAt%20line%3A1char%3A1%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%2B%20Remove-ServiceFabricApplication%20-ApplicationName%20fabric%3A%2FVoting%20-Forc%20...%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20OperationTimeout%3A%20(Microsoft.Servi...usterConnection%3AClusterConnection)%20%5BRemove-ServiceFabricApplication%5D%2C%20TimeoutException%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%2B%20FullyQualifiedErrorId%20%3A%20RemoveApplicationInstanceErrorId%2CMicrosoft.ServiceFabric.Powershell.RemoveApplication%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAt%20this%20scenario%2C%20there%20are%20PowerShell%20cmdlet%20switches%20which%20play%20a%20vital%20role%20and%20can%20help%20to%20mitigate%20the%20issue.%20I%20have%20tried%20using%20%3CSTRONG%3E%3CU%3E-ForceRemove%3C%2FU%3E%3C%2FSTRONG%3E%20switch.%20The%20following%20cmdlet%20helps%20me%20to%20delete%20all%20application%20that%20are%20distributed%20across%20multiple%20nodes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24ClusterName%3D%20%22clustername.cluster_region.cloudapp.azure.com%3A19000%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24Certthumprint%20%3D%20%22%7Breplace_with_ClusterThumprint%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EConnect-ServiceFabricCluster%20-ConnectionEndpoint%20%24ClusterName%20-KeepAliveIntervalInSec%2010%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-X509Credential%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-ServerCertThumbprint%20%24Certthumprint%26nbsp%3B%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-FindType%20FindByThumbprint%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-FindValue%20%24Certthumprint%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-StoreLocation%20CurrentUser%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-StoreName%20My%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24ApplicationName%20%3D%20%22fabric%3A%2Fvoting%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eforeach(%24node%20in%20Get-ServiceFabricNode)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7B%26nbsp%3B%26nbsp%3B%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%5Bvoid%5D(Get-ServiceFabricDeployedReplica%20-NodeName%20%24node.NodeName%20-ApplicationName%20%24ApplicationName%20%7C%20Remove-ServiceFabricReplica%20-NodeName%20%24node.NodeName%20-ForceRemove)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3ERemove-ServiceFabricApplication%20-ApplicationName%20%24ApplicationName%20-Force%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EThere%20might%20be%20situation%20where%20%3CSTRONG%3E-Force%3C%2FSTRONG%3E%20switch%20could%20also%20fail.%20In%20that%20scenario%20try%20with%3C%2FP%3E%0A%3CP%3E1)%20Move%20the%20Cluster%20Manager%20primary%20to%20another%20node%20and%20try%20to%20remove%20the%20app%20again%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3Ea)%20Move-ServiceFabricPrimaryReplica%20-PartitionId%20%5BCluster%20Manager%20System%20Service%20Partition%20Id%5D%20-ServiceName%20fabric%3A%2FSystem%2FClusterManagerService%3C%2FLI%3E%0A%3CLI%3Eb)%20Remove-ServiceFabricApplication%20-ApplicationName%20fabric%3A%2Fvoting%20-Force%20-ForceRemove%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2)%20If%20it%20still%20doesn't%20work%20due%20to%20stuck%20services%20or%20PLB%20affinity%2C%20try%20to%20move%20the%20primary%20for%20each%20partition%20of%20NamingService%20and%20try%20again.%3C%2FP%3E%0A%3CP%3EThere%20might%20also%20a%20scenario%20that%20the%20issue%20is%20happening%20with%20only%20one%20service%20distributed%20in%20multiple%20nodes%20instead%20of%20the%20whole%20application.%20Then%20use%20the%20below%20script%20which%20is%20like%20the%20one%20for%20application%20but%20with%20a%20little%20change%20which%20will%20only%20delete%20a%20specific%20Service.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24ClusterName%3D%20%22clustername.cluster_region.cloudapp.azure.com%3A19000%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24Certthumprint%20%3D%20%22%7Breplace_with_ClusterThumprint%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EConnect-ServiceFabricCluster%20-ConnectionEndpoint%20%24ClusterName%20-KeepAliveIntervalInSec%2010%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-X509Credential%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-ServerCertThumbprint%20%24Certthumprint%26nbsp%3B%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-FindType%20FindByThumbprint%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-FindValue%20%24Certthumprint%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-StoreLocation%20CurrentUser%20%60%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-StoreName%20My%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24ApplicationName%20%3D%20%22fabric%3A%2Fvoting%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%24ServiceName%20%3D%20%22fabric%3A%2FVoting%2FFEService%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eforeach(%24node%20in%20Get-ServiceFabricNode)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7B%26nbsp%3B%26nbsp%3B%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%5Bvoid%5D(Get-ServiceFabricDeployedReplica%20-NodeName%20%24node.NodeName%20-ApplicationName%20%24ApplicationName%20%7C%20Where-Object%20%7B%24_.ServiceName%20-match%20%24ServiceName%7D%20%7C%20Remove-ServiceFabricReplica%20-NodeName%20%24node.NodeName%20-ForceRemove)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3ERemove-ServiceFabricService%20-ServiceName%20%24ServiceName%20-Force%20%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20this%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1303747%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Service%20Fabric%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

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.