WWF Workflow persistence store exception

723 views Asked by At

We have a system that is using "WWF" as its workflow engine and the requests to proceed with the workflow faild frequently and the log is filled with this exception.

System.Runtime.DurableInstancing.InstancePersistenceException: The SqlWorkflowInstanceStore lock does not exist in the database. This could have occurred because the SQL Server is busy or because the connection was temporarily lost.

and it fires in this event (application.Aborted = (e) =>{}), Any ideas about how to solve this issue ?

Here is how I load the workflow and relase the lock

            //Create an instance of the workflow and its application and associate with workflow application.
            Activity workflow = Activator.CreateInstance(workflowType) as Activity;
            WorkflowApplication application = new WorkflowApplication(workflow);
            application.SynchronizationContext = SyncSynchronizationContext.SingletonInstance;

            //Hold the workflow store            
            application.InstanceStore = CreateInstanceStore(WorkflowDatabaseConnectionString);
            var instanceHandle = application.InstanceStore.CreateInstanceHandle(guid);
            var ownerCommand = new CreateWorkflowOwnerCommand();
            var view = application.InstanceStore.Execute(instanceHandle, ownerCommand, TimeSpan.FromDays(30));

            application.InstanceStore.DefaultInstanceOwner = view.InstanceOwner;
            // Do whatever needs to be dome with multiple WorkflowApplications

            if (pParticipant != null)
                application.Extensions.Add(pParticipant);

            //Register workflow application services from the external world
            ExternalRegisteredServices.ForEach(service => application.Extensions.Add(service));

            ReadOnlyCollection<BookmarkInfo> currentBookmarks = null;
            Dictionary<string, object> wfContextBag = null;

            application.PersistableIdle = (workflowApplicationIdleEventArgs) =>
            {
                currentBookmarks = workflowApplicationIdleEventArgs.Bookmarks;

                wfContextBag = workflowApplicationIdleEventArgs
                    .GetInstanceExtensions<WorkflowContext>()
                    .First()
                    .GetBag();
                return PersistableIdleAction.Unload;
            };

            application.OnUnhandledException = (e) =>
            {
                if (wfUnhandledExceptionEventHandler != null)
                    wfUnhandledExceptionEventHandler(e);
                return UnhandledExceptionAction.Abort;
            };

            application.Aborted = (e) =>
            {
                if (wfAbortedEventHandler != null)
                    wfAbortedEventHandler(e);
            };

            application.Completed = (e) =>
            {
                if (wfCompletedEventHandler != null)
                    wfCompletedEventHandler(e);
            };

            application.Load(guid);

            BookmarkResumptionResult resumptionResult = BookmarkResumptionResult.NotFound;
            if (!string.IsNullOrEmpty(bookmarkName))
                resumptionResult = application.ResumeBookmark(bookmarkName, null);

            if (resumptionResult != BookmarkResumptionResult.Success)
                currentBookmarks = application.GetBookmarks();

            var deleteOwnerCommand = new DeleteWorkflowOwnerCommand();
            application.InstanceStore.Execute(instanceHandle, deleteOwnerCommand, TimeSpan.FromSeconds(30));
            instanceHandle.Free();
1

There are 1 answers

0
Amin On

You can try using application.Unload(), this will help you to solve your Abort exception. By default, the unload operation must complete in 30 seconds. However, if it doesn't happens then Abort event gets triggered.