asyn icon indicating copy to clipboard operation
asyn copied to clipboard

asyn ports cannot be destroyed on IOC shutdown

Open exzombie opened this issue 1 year ago • 1 comments

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 avatar Mar 17 '23 17:03 exzombie