Alan Zeng
Alan Zeng

Reputation: 74

Azure Service Fabric FabricObjectClosedException

I have a stateful service that stores things in a IReliableDictionary. After deployed to local cluster, I restarted the primary node to test the failover, however, after I do that, the code StateManager.GetOrAddAsync>("MyDictionary") throws FabricNotPrimaryException, then in later trials it throws FabricObjectClosedException. What are some of the things that I can check to troubleshoot this?

Upvotes: 1

Views: 499

Answers (1)

Martin Liversage
Martin Liversage

Reputation: 106816

The basic way to troubleshoot errors like this is to catch and log the exception being thrown:

try
{
    using (var tx = StateManager.CreateTransaction())
    {
        await dictionary.AddOrUpdateAsync(tx, dto.Id, dto, (key, _) => dto);
        await transaction.CommitAsync();
    }
}
catch (FabricObjectClosedException ex)
{
    ServiceEventSource.Current.Message(ex.ToString());
    throw; // Pass the exception up as we only log it here.
}

However, your problem might be a very simple typo like a missing [DataContractAttribute] on a DTO class. In that case it might be easier to simply debug the problem to quickly understand and fix the problem. To do that you should add the System.Fabric.FabricObjectClosedException to Visual Studio and then enable "break when thrown" in the debugger:

  1. Show the Exception Settings window (Debug > Windows > Exception Settings)
  2. Select the Common Language Runtime Exceptions category in the list of exception categories
  3. Click the green + (plus) button to add a new exception type
  4. Type System.Fabric.FabricObjectClosedException in the text box and hit enter

When a new exception type is added the Break When Thrown check box is already checked.

Next time you execute your application in the debugger the debugger will break when a FabricObjectClosedException is thrown and you should be able to understand what went wrong.

Upvotes: 1

Related Questions