Skip to content
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

asyn ports cannot be destroyed on IOC shutdown #172

Open
exzombie opened this issue Mar 17, 2023 · 1 comment
Open

asyn ports cannot be destroyed on IOC shutdown #172

exzombie opened this issue Mar 17, 2023 · 1 comment

Comments

@exzombie
Copy link
Contributor

When the IOC terminates, the ports are not given a chance to clean up and release resources. Some resources, like memory, are not problematic: the OS will reclaim the memory of the terminated process. But there are more problematic resources, such as improperly closed connections to devices, that can consume resources on devices themselves.

I have attempted to work around this in my driver by registering a function with epicsAtExit() which deletes the driver, allowing the destructor to clean up. This causes a crash because EPICS does not stop scan threads on IOC exit. This necessitates disabling the port through asynManager before destroying the driver. The IOC no longer crashes on shutdown, but it does print spurious error messages when the scan threads poke the disabled port.

This workaround works well for our use case. It is not very "clean", however, because it leaves dangling references and simply trusts that they will not be used anymore.

Other users have noticed this behavior. The above workaround was proposed and discussed in the linked thread, and steps towards a better solution were outlined by Michael Davidsaver.

@exzombie exzombie mentioned this issue Mar 17, 2023
2 tasks
@daykin
Copy link
Contributor

daykin commented Mar 21, 2023

+1 to this being a nice improvement. It would make troubleshooting serious memory leaks in our drivers much easier if we can work towards knowing that the release branches of base, asyn, ADCore, etc. are valgrind memcheck/leak-check clean, without having to sift through tons of "leaks" that are actually just a negligible fixed cost that eventually gets freed up by the OS.

Plus, leaving cleanup work to the OS can mess up some unit test frameworks that destroy and rebuild the same objects for different tests.

Let me know if I can assist in any way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants