Windows NT 服务关闭问题

发布于 2024-08-30 03:51:30 字数 1375 浏览 5 评论 0原文

我开发了中间件,为我们组织内多个平台上的多个客户端应用程序提供 RPC 功能。该中间件是用 C# 编写的,并作为 Windows NT 服务运行。它处理诸如网络共享的文件访问、数据库访问等事务。中间件托管在两个运行 Windows Server 2008 的高端系统上。

当我们的一位服务器管理员重新启动计算机(主要是进行 Windows 更新)时,会出现严重的问题系统对我的 NT 服务的行为方式存在问题。我的服务旨在立即停止侦听新连接,立即开始拒绝现有连接上的新请求,并在收到来自 SCM 的 OnStop 或 OnShutdown 请求时尽快关闭。尽管如此,为了保持系统完整性,当前正在进行的操作可以继续一段合理的时间。通常服务器会在 30 秒内关闭(例如,当手动停止服务时)。但是,当系统被指示重新启动时,我的服务立即失去对网络驱动器和 UNC 路径的访问权限,从而导致任何打开的文件和对这些位置的部分写入出现数据完整性问题。我的服务确实将工作站(以及 SMB 重定向器)列为依赖项,因此我认为如果 Windows 尊重这些依赖项,则需要在停止工作站/重定向器之前停止我的服务。

基本上,我的应用程序被迫崩溃并烧毁,远程过程调用失败,并最终在超时时间过后(似乎约为 20-30 秒)被操作系统强制终止。

与 Windows 应用程序不同,我的 Windows NT 服务似乎没有任何权力来停止正在进行的系统关闭、延迟系统关闭,甚至没有机会在强制断开连接和关闭之前保存任何挂起的网络共享磁盘写入操作。 NT 服务开发人员如何在这种环境中拥有任何类型的应用程序完整性?为什么表单应用程序有机会在关闭之前完成其业务,而服务似乎没有这样的好处?

我尝试过:

通过 p/invoke 调用 SetProcessShutdownParameters 来尝试尽快通知我的应用程序关闭,以避免 Redirector 在我之前关闭。

使用小于或等于两分钟限制的值调用 ServiceBase.RequestAdditionalTime。

调整 WaitToKillServiceTimeout

我能想到的一切,让我的服务关闭得更快。

但最终,我仍然遇到大约 30 秒的问题时间,其中我的服务似乎还没有收到 OnShutdown 事件的通知,但由于重定向器不再为我的网络共享请求提供服务,请求失败。

这个问题应该如何解决?我可以做些什么来延迟或停止关闭,或者至少允许关闭我的活动任务,而不会使重定向器服务从我下面消失?我可以理解 Microsoft 正在尝试采取哪些措施来防止服务拖沓并显示关闭,但这对于 Windows 客户端操作系统来说似乎是一个伟大的目标,而不是服务器。我不希望我的服务器快速关闭,我想要操作完整性和正常关闭。

预先感谢您可以提供的任何帮助。

更新:我已经完成了确切的时间安排。在测试关闭中,我在 23:55:58 收到关闭通知,并注意到在 23:56:02 丢失了网络共享连接。因此,在四秒钟之内,我就失去了保存任何活动状态的能力。

I have developed middleware that provides RPC functionality to multiple client applications on multiple platforms within our organization. The middleware is written in C# and runs as a Windows NT Service. It handles things like file access to network shares, database access, etc. The middleware is hosted on two high end systems running Windows Server 2008.

When one of our server administrators goes to reboot the machine, primarily to do Windows Updates, there are serious problems with how the system behaves in regards to my NT Service. My service is designed to immediately stop listening for new connections, immediately start refusing new requests on existing connections, and otherwise shut down as rapidly as possible in the case of an OnStop or OnShutdown request from the SCM. Still, to maintain system integrity, operations that are currently in progress are allowed to continue for a reasonable time. Usually the server shuts down inside of 30 seconds (when the service is manually stopped for example). However, when the system is instructed to restart, my service immediately loses access to network drives and UNC paths, causing data integrity problems for any open files and partial writes to those locations. My service does list Workstation (and thus SMB Redirector) as a dependency, so I would think that my service would need to be stopped prior to Workstation/Redirector being stopped if Windows were honoring those dependencies.

Basically, my application is forced to crash and burn, failing remote procedure calls and eventually being forced to terminate by the operating system after a timeout period has elapsed (seems to be on the order of 20-30 seconds).

Unlike a Windows application, my Windows NT Service doesn't seem to have any power to stop a system shutdown in progress, delay the system shutdown, or even just the opportunity to save out any pending network share disk writes before being forcibly disconnected and shutdown. How is an NT Service developer supposed to have any kind of application integrity in this environment? Why is it that Forms Applications get all of the opportunity to finish their business prior to shutdown, while services seem to get no such benefits?

I have tried:

Calling SetProcessShutdownParameters via p/invoke to try to notify my application of the shutdown sooner to avoid Redirector shutting down before I do.

Calling ServiceBase.RequestAdditionalTime with a value less than or equal to the two minute limit.

Tweaking the WaitToKillServiceTimeout

Everything I can think of to make my service shutdown faster.

But in the end, I still get ~30 seconds of problematic time in which my service doesn't even seem to have been notified of an OnShutdown event yet, but requests are failing due to redirector no longer servicing my network share requests.

How is this issue meant to be resolved? What can I do to delay or stop the shutdown, or at least be allowed to shut down my active tasks without Redirector services disappearing out from under me? I can understand what Microsoft is trying to do to prevent services from dragging their feet and showing shutdowns, but that seems like a great goal for Windows client operating systems, not for servers. I don't want my servers to shutdown fast, I want operational integrity and graceful shutdowns.

Thanks in advance for any help you can provide.

UPDATE: I've done the exact timings. In a test shutdown, I got shutdown notification at 23:55:58 and noticed losing network share connectivity at 23:56:02. So within four seconds, I've lost the ability to save out any active state.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为守护你 2024-09-06 03:51:30

这个问题:https://serverfault.com/questions/34427/windows-service-dependencies on ServerFault应该回答你自己的。它链接到这篇文章: http://blogs.technet.com/askperf/archive/2008/02/04/ws2008-service-shutdown-and-crash-handling.aspx,这应该可以帮助您获得预关闭通知和服务关闭命令。

This question: https://serverfault.com/questions/34427/windows-service-dependencies on ServerFault should answer your own. It links to this article: http://blogs.technet.com/askperf/archive/2008/02/04/ws2008-service-shutdown-and-crash-handling.aspx, which should help you get pre-shutdown notification and service shutdown ordering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文