Win32 命名事件的间歇性问题
当进程在不同的用户上下文中运行时,遇到与命名事件相关的间歇性问题:此类事件句柄的 WaitForSingleObject(以及 WaitForMultipleObjects)失败并显示 WAIT_FAILED(GetLastError 返回 6 - 无效句柄值)。
我们有一个应用程序可以在用户帐户下在 Windows 计算机上安排任务,并且在某些任务完成后会出现问题。
应用程序 (JobManager) 的服务部分在用户帐户 (CreateProcessAsUser) 下启动可执行文件 (JobLeader) 来运行用户任务,并等待指定事件发出信号。 手动重置命名事件由 JobLeader 在“Global\”命名空间中创建,并在用户任务完成时发出信号。
JobManager 在循环中等待,延迟 10 秒调用 WFMO(WaitForMultipleObjects),以查看指定事件或 JobLeader 进程句柄是否收到信号。
由 JobManager 通过 OpenEvent API 调用打开的定期命名的事件句柄会导致 WFMO(之后还会调用 WFSO 来识别哪个句柄已损坏)返回 WAIT_FAILED,错误代码为 6 -“句柄值无效”。 重新打开事件后,此错误可能会消失,也可能不会 - WFMO 可能会因句柄值无效而再次返回 WAIT_FAILED。
有趣的是,它可能会通过几十个任务而不会出现此错误,然后 - 依次很少有任务出现此错误。用于测试的任务是相同的 - 只是一个 cmd.exe 脚本、转储环境。
有人对此有什么想法吗?
问候, 亚历克斯
Experiencing intermittent issues, related to named events when processes are running in different user contexts: WaitForSingleObject (and WaitForMultipleObjects too) for such event handle fails with WAIT_FAILED (GetLastError returns 6 - Invalid handle value).
We have an application to schedule tasks on Windows machines under user accounts, and issue happens after some tasks are completed.
Service part of application (JobManager) starting executable (JobLeader) under user account (CreateProcessAsUser) to run user task, and waiting for named event to be signaled.
Manual reset named event is created by JobLeader in the "Global\" namespace and signaled when user task is completed.
JobManager waiting in the loop, calling WFMO(WaitForMultipleObjects) with delay of 10 seconds, to see if named event or JobLeader process handle are signaled.
Periodically named event handle, opened by JobManager through OpenEvent API call, causes WFMO (WFSO is also called after to identify which handle is broken) to return WAIT_FAILED, with error code 6 - "Invalid handle value".
After reopening the event, this error may gone, or may not - WFMO may again returns WAIT_FAILED because of invalid handle value.
Interesting, that it may pass few dozens tasks without this error, and then - sequentially few tasks have it. Tasks used for testing are identical - just a cmd.exe script, dumping environment.
Anyone have ideas about this?
Regards,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在 JobManager 中创建事件,然后在“JobLeader”中打开它?如果没有,如何在两个进程之间传递事件句柄(和/或名称)?
我的直觉告诉我这是一个竞争条件......
Do you create the event in your JobManager and then open it in the 'JobLeader'? If not, how do you communicate the event handle (and/or name) between the two processes?
My gut tells me it's a race condition...