服务在 StackOverflowException 上继续 [英] Service to continue on StackOverflowException

查看:26
本文介绍了服务在 StackOverflowException 上继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用第三方库来操作 Pdf.我们的应用程序作为 Windows 服务运行,每月处理数千个文件.偶尔有人上传格式错误的 Pdf,这会使库运行异常并最终抛出 StackOverflowException.

We use a third party library to manipulate Pdf's. Our application runs as a Windows service and handles thousands of files every month. Once in a while someone uploads a malformed Pdf, which makes the library run amok and eventually throw a StackOverflowException.

库制造商在过去 2 年里没有修复错误,我们不能在有人觉得它的时候让我们的生产崩溃.

The library manufacturer has not fixed the error over the last 2 years, and we can't have our production crash when someone feels like it.

自动重新启动服务似乎不是一种选择,因为应用程序随后会重试格式错误的文件.由于我们并行处理很多文件,启动时无法知道哪个是格式错误的.

Automatically restarting the service does not seem like an option, as the application would then retry the malformed file. Since we process many files in parallel, we cannot know which is the malformed when starting.

由于默认情况下无法捕获stackoverflows,我想知道是否可以调整服务的CLR以无论如何捕获异常.

Since stackoverflows can't be catched by default, I would like to know if I can tweak the CLR of the service to catch the exception anyway.

推荐答案

您可以重新构建应用程序以创建新的子进程,每个子进程都有自己的库实例,以执行工作.

You could re-architect the application to create new child processes, each with its own instance of the library, to perform the work.

最重要的是,使用这种方法,失败的实例不会使整个应用程序崩溃,也不会使其他子进程随之中断.您还有一个优势,即管理器进程可以跟踪哪些文件正在处理(以及在哪个进程上),因此它会知道哪些文件在失败后不重试.

Most importantly, with this approach the failing instance doesn't crash the entire application or take the other child processes down with it. You also have the advantage that the manager process can keep track of which files are in progress (and on which process) so it would know which files to not retry after a failure.

这篇关于服务在 StackOverflowException 上继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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