简体   繁体   中英

AppFabric Hosted Workflow does not always reload after delay/unload

I have a WCF Windows Workflow (4.5) Workflow Service hosted under IIS and using AppFabric 1.1. The workflow instances are long-running (up to about a week), but much of the time is spent in Delay activities.

This seemed to work fine at first, but when running multiple instances of the workflow at the same time (2+ instances causes this), some of them just never wake up once they've unloaded from memory during the Delay step. When I look at the logs, the errors I find all look like this:

              System.OperationCanceledException: The execution of InstancePersistenceCommands has been canceled because the InstanceHandle was freed.
          at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
          at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.WaitAndHandleStoreEventsCallback(IAsyncResult result)

Unfortunately, I'm not finding any useful information on that error message.

The SuspensionExceptionName and SuspensionReason fields in the AppFabric Persisted Instances Table show System.NullReferenceException: Object reference not set to an instance of an object. But this doesn't happen inside my workflow, only outside.

Additional Info:

  • I'm running the activity as a Fire & Forget (receive activity, no send)
  • My workflow calls into other WCF services to fetch data.
  • I am running this on Server 2012 R2, IIS 8 (not azure)
  • Workflow Persistence is working. I can reset IIS, reboot... its just when I run 2 instances that it has problems.
  • I'm definitely not hitting any kind of throttling limits. While the workflow deals with a few MB of data, this issue happens at 2+ instances.

Any idea what might be happening here?

Edit: I realized I found more information on how the issue operates and never added it to the question. When the delay issue happens, it operates a lot like a static variable getting written by 2 threads.

Here's a visualization:

WF1 Start ---->Do Stuff--->Sleep------------*1----->Cancelled Exception at some point

------WF 2 Start---->Do Stuff------->Sleep->Wake up---------*2------>More Stuff---->End Successfully

*1 - When WF Instance 1 Should Wake up (Same time as WF 2 wakes)

*2 - When WF Instance 2 Should have woken up (Seems to be ignored)

Before anyone asks... I got rid of every static variable, method, class in my code. Nothing is static anymore.

I've been struggling with similar issues for quite a while. I use WFW4 and I find similar errors when a workflow instance is in a long delay.

I don't know what the cause of the problem is, but I have a work around that you might find helpful.

In my case, the errors I get are from Workflow Management Service and say: Failed to invoke service management endpoint at 'net.pipe://.svc' to activate service '/Alerts/Workflows/.xamlx'. Exception: 'Access is denied.'

These errors start happening sometime between 6 and 30 hours after the instance goes into a long delay.

I have found that if I create a new instance of the workflow when the first instance is in delay and the errors are happening, then Workflow Management Service is able to resume interacting with the first sleeping instance.

So, I made a new workflow whose sole purpose is to periodically launch and then kill instances of the workflow that contains the long delay.

It actually gets a bit more complicated to make this work. I wanted this new workflow to also go to sleep between times when it creates and kills a new instance of the first workflow. But this going to sleep causes the instance of the new workflow to suffer the same problem as the first workflow. So, I modified the new workflow so it does the following: -- delay for some rather short period, such as 30 minutes -- create an instance of the first workflow -- wait a minute -- kill the just-created instance of the first workflow -- create a new instance of this new error-preventing workflow -- terminate

Since having done this, I no longer get the Access is Denied error from Workflow Management Service!

Hope this helps

Turns out my first answer was not correct, but I believe this answer is right, and solves the issue ChrisG is having.

My workaround did not actually work. Took a while for the problem to resurface. 29 hours to be precise - the default time it takes for an app pool to recycle.

So for me, the solution was to make my app pool not recycle. When an app pool recycles while a workflow instance is in a delay activity, the workflowManagementService is not able to wake up the instance and throws Access is Denied errors. If you create a new instance of the workflow after the app pool has recycled, the first instance will pick up where it left off, but sometimes still has problems, which is what I believe is happening to ChrisG.

ChrisG, looking at your visualization, is it possible that an appPool is recycling during the time wf1 is sleeping? I believe that is the cause the exception. If you then launch a new wf instance after *2 has passed (and if an app pool recycle happened prior to *1), that will wake up both wf1 and wf2, but wf1 won't work properly (at least in my experience)

Also, this happens after iisresets and server reboots. To handle those, you need to use IIS7 which allows the web application (as well as the web site) which is hosting the xamlx files to autostart after an iisreset or server reboot. This option is not available in IIS6. See http://www.postseek.com/meta/991815402b369e71ce925cde47ac907d for details

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM