-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SysFsDriver keeps gpio line in-use when application crashes #1992
Comments
Thanks for this observation. I don't know whether there's an easy fix for this problem, since it feels awkward having to use the sysfs driver to properly initialize libgpiod after such a crash. |
@HakanL Could you please post the stack trace of the fault when running on libgpiod? I don't have a RPi here now. |
@raffaeler Sure, here's the stack trace (but IMHO the issue is in the SysFsDriver, the Gpio line is marked as in-use even when the process is completely gone.
This is what the output of gpioinfo shows: |
Understood, it may not be possible to release the resource in the scenario (in the SysFsDriver). This is the first time I've seen an application on Linux keeping resources after it's killed, which is the reason why I wasn't expecting this behavior (and waited a long time to reboot). I also tested to run the application again with the SysFsDriver, and exiting it properly (after it had crashed before), to see if it would release the line. The application runs fine (using the gpio line), but it doesn't release the line when exiting properly. It is possible of course that it's an issue with the SysFs "system", but that is outside my expertise. |
Yes, I got this, but I wanted to understand where exactly the problem happens. I guess that the SysFsDriver should subscribe some process-termination hook to close the native resource, but I am not familiar with that code. |
[Triage] @HakanL can you share minimal repro? We're having hard time telling if your scenario is by design or not |
@krwq I have a link to a repo above, it's very simple and just shows that if there's an exception (any exception, it's not related to the actual exception I'm throwing, that's just to show the issue) then the gpio line is captured even after the process terminates. In other words I can't re-run the application until I reboot. |
Oh, got it, thanks for the repro, we somehow missed that originally. What we were more curious about was whether or not you had wrapped the GpioController inside a using statement (as we would have expected that Dispose would cleanup resources), but looks like you are doing that so we should take another look to see what is going on and why is Dispose not cleaning up those files. |
@HakanL thanks for the repro that was impeccable. I made some tests and the code inside GpioController and SysFsDriver is fine. More specifically, this comment explains the reasons why it has not been already fixed. We will discuss again this issue in the Triage to understand whether there is some other possible solution to resolve this scenario. |
@raffaeler Thanks for looking into it. But why would it then be different for the |
I am not sure to understand your question. |
Sorry, used the wrong name. I meant why is it different for the LibGpiodDriver driver? It doesn't seem to have the same issue. |
The |
Ah, then I understand, thank you. |
BTW, generally speaking, you may always want to use |
Makes sense, I can't remember why I used the SysFsDriver, it may have just been an attempt to see the difference. But I spent a long time trying to figure out why I would get the resource busy error (always expecting an issue with your own code first of course), so I figured I should report it as it was inconsistent between the drivers. |
The reason may be very simple: the libgpiod driver is not installed by default on Raspbian. So you had to |
Ahh, I think you're right, I used the default constructor and it only worked once (because I had a crash). That's when I started down the path of drivers. Several months ago, hard to remember ;) |
we need to re-triage this with new info |
I think the problem here is very simple:
I think there is no perfect solution to point 1, since there is no way to clean up a file if the application crashes or worse, is killed. The problem does not happen if either:
|
@pgrawehr I made some tests and the problem has a different nature. So yes, the pin is left open but this is a problem peculiar to our library as the SysFsDriver, for its nature, uses files that are preserved after the process get killed. But again, I agree with @krwq that we should talk about this in the next triage, now that the we know the exact cause of the issue. |
[Triage] Regarding this thread, there is nothing really that can be done on the .NET IoT side. The only recommendation is to use try/catch along your application and making sure it won't crash. |
Few seconds ago, it was committed a change in .NET 9 repo that adopts a new exception handling mechanism (on by default) that solves this issue. Of course, none of us had the opportunity to test this in the context of this thread. |
Describe the bug
When using the SysFsDriver and the application crashes then the Gpio line is left in-use and can't be used again with the libgpiod driver.
Steps to reproduce
If I try to run the demo app again then that works, but if I switch to use libgpiod instead then I'll get error code 16 (resource in use / EBUSY).
Expected behavior
Any gpio resource allocated by the SysFsDriver should be released, even if the application crashes.
Actual behavior
Used gpio lines are kept in-use.
Versions used
Tracking external issue: dotnet/runtime#79155
The text was updated successfully, but these errors were encountered: