WF4 InstancePersistenceCommand 中断 [英] WF4 InstancePersistenceCommand interrupted

查看:53
本文介绍了WF4 InstancePersistenceCommand 中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows 服务,运行工作流.工作流是从数据库加载的 XAML(用户可以使用重新托管的设计器定义自己的工作流).它配置了 SQLWorkflowInstanceStore 的一个实例,以在空闲时保持工作流.(它基本上源自 Microsoft 的 WCF/WF 示例中 \ControllingWorkflowApplications 中的示例代码).

但有时我会收到如下错误:

System.Runtime.DurableInstancing.InstanceOwnerException:InstancePersistenceCommand 的执行被中断,因为所有者 ID 'a426269a-be53-44e1-8580-4d0c396842e8' 的实例所有者注册已无效.此错误表明此所有者锁定的所有实例的内存中副本已过时,应与 InstanceHandles 一起丢弃.通常,最好通过重新启动主机来处理此错误.

我一直在寻找原因,但是在开发中很难重现,但是在生产服务器上,我偶尔会发现它.我发现的一个提示:当我查看 LockOwnersTable 时,我发现 LockOnwersTable lockexpiration 设置为 01/01/2000 0:0:0 并且它不再更新,而在正常情况下,根据主机锁更新期...

那么,为什么 SQLWorkflowInstanceStore 会停止更新此 LockExpiration 以及如何检测其原因?

解决方案

这是一个旧线程,但我只是偶然发现了同样的问题.

Damir's Corner 建议检查实例句柄是否还在在调用实例存储之前有效.我在此引用整个帖子:

<块引用>

Workflow Foundation 的某些方面仍然没有很好的记录;持久性框架就是其中之一.以下代码段通常用于设置实例存储:

var instanceStore = new SqlWorkflowInstanceStore(connectionString);instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30);var instanceHandle = instanceStore.CreateInstanceHandle();var view = instanceStore.Execute(instanceHandle,new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(10));instanceStore.DefaultInstanceOwner = view.InstanceOwner;

<块引用>

很难找到所有这一切的详细解释做;老实说,通常没有必要.至少不是,直到你开始遇到问题,比如 InstanceOwnerException:

InstancePersistenceCommand 的执行被中断,因为所有者 ID 的实例所有者注册9938cd6d-a9cb-49ad-a492-7c087dcc93af"已失效.这个错误表示由此锁定的所有实例的内存副本所有者已经陈旧,应该被丢弃,连同实例句柄.通常,最好通过重新启动来处理此错误主持人.

该错误与 HostLockRenewalPeriod 属性密切相关它定义了多长时间获得的实例句柄是有效的,而不是更新.如果您尝试在实例存储时监控数据库实例化了一个有效的实例句柄,你会注意到[System.Activities.DurableInstancing].[ExtendLock] 被调用定期.这个存储过程负责更新处理.如果由于某种原因无法在指定的时间内调用HostLockRenewalPeriod,会抛出上面提到的异常尝试持久化工作流时.一个典型的原因是由于维护或联网而暂时无法访问数据库问题.这不是经常发生的事情,但它必然会发生如果您有一个长期存在的实例存储,例如在一个不断运行工作流主机,例如 Windows 服务.

幸运的是,一旦你解决了这个问题,问题就不是那么难知道它的原因.在使用实例存储之前,您应该始终检查句柄是否仍然有效;并更新它,如果不是:

if (!instanceHandle.IsValid){instanceHandle = instanceStore.CreateInstanceHandle();var view = instanceStore.Execute(instanceHandle,new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(10));instanceStore.DefaultInstanceOwner = view.InstanceOwner;}

<块引用>

这绝对比重启主机的侵入性小,建议通过错误消息.

I have a windows service, running workflows. The workflows are XAMLs loaded from database (users can define their own workflows using a rehosted designer). It is configured with one instance of the SQLWorkflowInstanceStore, to persist workflows when becoming idle. (It's basically derived from the example code in \ControllingWorkflowApplications from Microsoft's WCF/WF samples).

But sometimes I get an error like below:

System.Runtime.DurableInstancing.InstanceOwnerException: The execution of an InstancePersistenceCommand was interrupted because the instance owner registration for owner ID 'a426269a-be53-44e1-8580-4d0c396842e8' has become invalid. This error indicates that the in-memory copy of all instances locked by this owner have become stale and should be discarded, along with the InstanceHandles. Typically, this error is best handled by restarting the host.

I've been trying to find the cause, but it is hard to reproduce in development, on production servers however, I get it once in a while. One hint I found : when I look at the LockOwnersTable, I find the LockOnwersTable lockexpiration is set to 01/01/2000 0:0:0 and it's not getting updated anymore, while under normal circumstances the should be updated every x seconds according to the Host Lock Renewal period...

So , why whould SQLWorkflowInstanceStore stop renewing this LockExpiration and how can I detect the cause of it?

解决方案

This is an old thread but I just stumbled on the same issue.

Damir's Corner suggests to check if the instance handle is still valid before calling the instance store. I hereby quote the whole post:

Certain aspects of Workflow Foundation are still poorly documented; the persistence framework being one of them. The following snippet is typically used for setting up the instance store:

var instanceStore = new SqlWorkflowInstanceStore(connectionString);
instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30);
var instanceHandle = instanceStore.CreateInstanceHandle();
var view = instanceStore.Execute(instanceHandle, 
    new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(10));
instanceStore.DefaultInstanceOwner = view.InstanceOwner;

It's difficult to find a detailed explanation of what all of this does; and to be honest, usually it's not necessary. At least not, until you start encountering problems, such as InstanceOwnerException:

The execution of an InstancePersistenceCommand was interrupted because the instance owner registration for owner ID '9938cd6d-a9cb-49ad-a492-7c087dcc93af' has become invalid. This error indicates that the in-memory copy of all instances locked by this owner have become stale and should be discarded, along with the InstanceHandles. Typically, this error is best handled by restarting the host.

The error is closely related to the HostLockRenewalPeriod property which defines how long obtained instance handle is valid without being renewed. If you try monitoring the database while an instance store with a valid instance handle is instantiated, you will notice [System.Activities.DurableInstancing].[ExtendLock] being called periodically. This stored procedure is responsible for renewing the handle. If for some reason it fails to be called within the specified HostLockRenewalPeriod, the above mentioned exception will be thrown when attempting to persist a workflow. A typical reason for this would be temporarily inaccessible database due to maintenance or networking problems. It's not something that happens often, but it's bound to happen if you have a long living instance store, e.g. in a constantly running workflow host, such as a Windows service.

Fortunately it's not all that difficult to fix the problem, once you know the cause of it. Before using the instance store you should always check, if the handle is still valid; and renew it, if it's not:

if (!instanceHandle.IsValid)
{
    instanceHandle = instanceStore.CreateInstanceHandle();
    var view = instanceStore.Execute(instanceHandle, 
        new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(10));
    instanceStore.DefaultInstanceOwner = view.InstanceOwner;
}

It's definitely less invasive than the restart of the host, suggested by the error message.

这篇关于WF4 InstancePersistenceCommand 中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆