-
Notifications
You must be signed in to change notification settings - Fork 33
MMALCamera.ProcessAsync sometimes hangs indefinitely #198
Comments
I'm using the following method to try to detect the timeout.
I then use this in the following way:
If the cam.ProcessAsync method hangs, then the CancelAfterAsync method should detect this and return false. [13:54:54 DBG] Running CaptureRawData It then hangs indefinitely on the return null line inside CaptureRawData. If anyone can just help me with how to detect the hang and retry safely then that would be great. |
I'm struggling for time to invest in MMALSharp at the moment due to work commitments. My advice would be to enable verbose logging using You don't say in your message whether you're using .NET Core or Mono. If you're using .NET Core, please can you try the same application under the latest version of Mono and see if you can reproduce? I have encountered issues like this in the past, although it is very difficult to understand the root cause and which component is actually at fault; whether it be the MMALSharp library itself, the MMAL library we're consuming, hardware related, or an issue with the platform (.NET Core/Mono). |
I've enabled I'm logging memory usage every minute in a python script completely independently to this and it stays a solid 25-30% memory usage over 4-5 hours so there's almost definitely not a memory leak. I'm using .NET Core. I may try Mono as well. I've also tried removing all async and changing to use the following:
It reaches the "Camera might have locked up" line and then hangs outside the Task.Run, which is just bizarre. |
It's possible that it's locking while disposing either one of these using statements:
I'm going to run some further tests and report back. |
I think the issue will be a background thread that is failing to complete due to the buffer sending issue I spoke about previously. The native MMAL library sends buffer headers to the callback handlers (function pointers) which invokes a background thread. If an operation on those background threads fails to complete then the application will hang indefinitely because it's unable to terminate cleanly until all threads have completed. As you're processing raw data, the callback will be sent to here and in turn here. The issue will most probably be happening here. Regarding the logging, I think the output you see will depend on the Log Level you've set against Serilog and you will want to set a minimum level of "Debug". The output will then go to your desired target i.e. console/file. It will be interesting to find out whether it's the sending or the releasing of the buffer that's causing the lock but I would encourage you to try Mono to see if the issue is .NET Core specific. |
Ok, so the locking up was also happening during disposing one of those two usings in my previous comment. [08:01:14 DBG] var renderer = new MMALNullSinkComponent(); Although it's definitely not out of memory, the memory usage is only 30% when this happens. |
I've found an acceptable workaround that is a good enough solution for me for now. I can detect the first hang and just exit the program. I've configured it as a linux service that will automatically re-run if it exits. Since the program is running a continual loop anyway, it's not really detrimental if it exits and starts running again, and it only does so a couple of times per day. |
Hello, I'm running the following code on my Raspberry Pi:
This captures an image to memory and returns it as a byte array.
Mostly it works great. I'm running this to capture an image every 10 seconds or so.
Randomly, after a few hours the program freezes on the line "await cam.ProcessAsync" which I can tell because of the serilog logging.
Having left it for several hours, it never recovers, it just hangs forever on that line and I have to Ctrl+C to kill the program.
If I run it again it can capture images again without issue, only to hang again after a few hours in the same place.
I read that this may be caused due to power issues, but I'm using an official RPi power supply without any other peripherals.
Regardless, even if it is caused by intermittent power brown out, it doesn't really matter to me if it fails to capture one image every few hours, I just want to be able to detect the failure and try again. As it stands, I can't retry since the main thread completely locks up.
It's an absolute requirement that I capture the image to memory, I can't use the other methods in MMALSharp to capture the image to disk, since I'm doing some post filtering on the image in memory after capturing it, and then deciding that I only want to save certain images to disk if they pass certain tests.
I've attempted to detect the hang with a timeout and retry, but this also hangs with some strange behaviour. This is already quite a long post so I'll post as a reply my attempt to work around the issue.
The text was updated successfully, but these errors were encountered: