Sicos1977 / TesseractOCR

A .net library to work with Google's Tesseract
161 stars 20 forks source link

SEHException: External component has thrown an exception #34

Closed lobbo232 closed 1 year ago

lobbo232 commented 1 year ago

I've got your package set up in my project and it has been running fine locally for quite a while now.

We recently deployed to our live environment where it also works, but only for a few days.

After a while the tesseract engine will fail to initialise and this exception will be thrown: System.Runtime.InteropServices.SEHException: External component has thrown an exception.

Once the issue starts occurring, the only way to stop it from happening for another few days is to restart the entire site.

Stack trace:

{"level":0,"method":"InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiInit4","assembly":"InteropRuntimeImplementer.TessApiSignaturesInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","line":0}
{"level":1,"method":"TesseractOCR.Interop.TessApi.BaseApiInit","assembly":"TesseractOCR, Version=5.2.14.0, Culture=neutral, PublicKeyToken=null","line":0}
{"level":2,"method":"TesseractOCR.Engine.Initialize","assembly":"TesseractOCR, Version=5.2.14.0, Culture=neutral, PublicKeyToken=null","line":0}

I'm not sure what to do here. A single instance is created and used per request on our API. Everything is being disposed of correctly after it's used.

Running version 5.2.14

Sicos1977 commented 1 year ago

Is this on a Windows Service?

lobbo232 commented 1 year ago

Hey @Sicos1977, thanks for replying so quickly!

This is a on a Windows App Service hosted on Azure.

Sicos1977 commented 1 year ago

Is there any extra information in the eventviewer about why the exception is thrown... I never have seen this issue before

lobbo232 commented 1 year ago

Event logs don't have anything recorded for that period of time. The apps service memory usage at the time was ~60%, and CPU was ~30%.

Here's some more info from the exception logs

timestamp [UTC]
2023-03-14T09:24:27.6030182Z
problemId
System.Runtime.InteropServices.SEHException at InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiInit4
type
System.Runtime.InteropServices.SEHException
assembly
InteropRuntimeImplementer.TessApiSignaturesInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
method
InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiInit4
outerType
System.Runtime.InteropServices.SEHException
outerMessage
System.Runtime.InteropServices.SEHException: External component has thrown an exception.
outerAssembly
InteropRuntimeImplementer.TessApiSignaturesInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
outerMethod
InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiInit4
severityLevel
1
details
[{"id":"62711381","outerId":"0","type":"System.Runtime.InteropServices.SEHException","message":"System.Runtime.InteropServices.SEHException: External component has thrown an exception.","parsedStack":[{"level":0,"method":"InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiInit4","assembly":"InteropRuntimeImplementer.TessApiSignaturesInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","line":0},{"level":1,"method":"TesseractOCR.Interop.TessApi.BaseApiInit","assembly":"TesseractOCR, Version=5.2.14.0, Culture=neutral, PublicKeyToken=null","line":0},{"level":2,"method":"TesseractOCR.Engine.Initialize","assembly":"TesseractOCR, Version=5.2.14.0, Culture=neutral, PublicKeyToken=null","line":0},{"level":3,"method":"Application.Helpers.TesseractHelper.GetTesseract5Engine","assembly":"Application, Version=1.3.23067.3, Culture=neutral, PublicKeyToken=null","line":15,"fileName":"D:\\a\\1\\s\\Application\\Helpers\\TesseractHelper.cs"},{"level":4,"method":"Application.Services.OCRService.GetOCRReadResults","assembly":"Application, Version=1.3.23067.3, Culture=neutral, PublicKeyToken=null","line":269,"fileName":"D:\\a\\1\\s\\Application\\Services\\OCRService.cs"}],"severityLevel":"Information"}]
0
{"id":"62711381","outerId":"0","type":"System.Runtime.InteropServices.SEHException","message":"System.Runtime.InteropServices.SEHException: External component has thrown an exception.","parsedStack":[{"level":0,"method":"InteropRuntimeImplementer.TessApiSignaturesInstance.TessApiSignaturesImplementation.BaseApiInit4","assembly":"InteropRuntimeImplementer.TessApiSignaturesInstance, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","line":0},{"level":1,"method":"TesseractOCR.Interop.TessApi.BaseApiInit","assembly":"TesseractOCR, Version=5.2.14.0, Culture=neutral, PublicKeyToken=null","line":0},{"level":2,"method":"TesseractOCR.Engine.Initialize","assembly":"TesseractOCR, Version=5.2.14.0, Culture=neutral, PublicKeyToken=null","line":0},{"level":3,"method":"Application.Helpers.TesseractHelper.GetTesseract5Engine","assembly":"Application, Version=1.3.23067.3, Culture=neutral, PublicKeyToken=null","line":15,"fileName":"D:\\a\\1\\s\\Application\\Helpers\\TesseractHelper.cs"},{"level":4,"method":"Application.Services.OCRService.GetOCRReadResults","assembly":"Application, Version=1.3.23067.3, Culture=neutral, PublicKeyToken=null","line":269,"fileName":"D:\\a\\1\\s\\Application\\Services\\OCRService.cs"}],"severityLevel":"Information"}
id
62711381
message
System.Runtime.InteropServices.SEHException: External component has thrown an exception.
Sicos1977 commented 1 year ago

You could try to turn on logging and see if that gives a clue about why this is happening. Make sure you have enough disk space because it can go quickly if you store it in a file. If disk space is limited you need to make something that deletes old logging automatlicly.

Sicos1977 commented 1 year ago

You could also try to update to the latest version 5.3.2, this also uses the latest Tesseract version 5.3. Or check the solved issues between the 5.2 and 5.3 tesseract version and see if something has been fixed that could explain the problem you are having.

lobbo232 commented 1 year ago

Thanks @Sicos1977. I've enabled logging and will see what that shows up. It might take a couple of days for the issue to start occurring again though. In the mean time I've been trying to upgrade to 5.3.2 but I'm having an issue with System.Memory version not being found which I haven't resolved yet.

Sicos1977 commented 1 year ago

If you have issues with specific version of System.Memory you could always try to use a binding redirect to force it to use another version.

Sicos1977 commented 1 year ago

Any errors lately?

lobbo232 commented 1 year ago

I have enabled all the logging you suggested but it hasn't happened again yet.

23 Mar 2023 05:36:37 Kees @.***>:

Any errors lately?

— Reply to this email directly, view it on GitHub[https://github.com/Sicos1977/TesseractOCR/issues/34#issuecomment-1480629386], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AEGMQA2K3SXVZKFI6XHPF3LW5POOHANCNFSM6AAAAAAV2JI5RU]. You are receiving this because you authored the thread.[Tracking image][https://github.com/notifications/beacon/AEGMQA5SJUJJREWZGT2KHU3W5POOHA5CNFSM6AAAAAAV2JI5RWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSYICOIU.gif]

Sicos1977 commented 1 year ago

Did you upgrade to the latest version?

lobbo232 commented 1 year ago

Yes but it hasn't been deployed yet as the dependency issue I had to fix required more thorough testing from QA.

The new version certainly appears more accurate and faster though which is a bonus.

23 Mar 2023 08:28:31 Kees @.***>:

Did you upgrade to the latest version?

— Reply to this email directly, view it on GitHub[https://github.com/Sicos1977/TesseractOCR/issues/34#issuecomment-1480773913], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AEGMQAYKSQ4QICEVFX2V4VLW5QCSZANCNFSM6AAAAAAV2JI5RU]. You are receiving this because you authored the thread.[Tracking image][https://github.com/notifications/beacon/AEGMQA45IFWDLMM7B3NWQGTW5QCSZA5CNFSM6AAAAAAV2JI5RWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSYILIRS.gif]

lobbo232 commented 1 year ago

It's just found out it has started occurring this morning again. I enabled logging as you suggested for both Application and web server but other than showing the request has happened it isn't giving any additional information to help diagnose the cause of the issue.

I will look at deploying the updated version today, then it'll be another wait for it to occur again I think.

Sicos1977 commented 1 year ago

I only can think of some kind of bug in Tesseract OCR that build up in time before it fails. Hope it is gone in the latest relase otherwise we need to keep digging

lobbo232 commented 1 year ago

Unfortunately last week this issue occurred again running the latest version of the package! Any thoughts on what we could do next to investigate the cause?

lobbo232 commented 1 year ago

@Sicos1977 have you had any time to think about this?

Sicos1977 commented 1 year ago

I have no idea but I did see that there is a new Tesseract version 5.3.1 so I'm planning to make a new nuget package this week with that one in it.

Sicos1977 commented 1 year ago

I updated Tesseract to 5.3.1 hope this makes any difference

lobbo232 commented 1 year ago

Thanks I'll give it a try when I can.

Do you think this issue is related to the tesseract library then and not from this package?

How are the interop services used?

Sicos1977 commented 1 year ago

I don't have any clue where to look for this issue. Interop is always tricky and when something crahes only after a long period then it is very hard to figure out where it is comming from. It is much easier to debug when it just failes every time.