yarp icon indicating copy to clipboard operation
yarp copied to clipboard

Improve closing behavior when attempting to close a device implementing the service interface

Open S-Dafarra opened this issue 1 year ago • 2 comments
trafficstars

I am implementing a device which can close prematurely depending on the internal state. I want yarpdev to be notified when this happens and close consequently.

In order to have this behavior, I implemented the IService interface. But then, if I press CTRL+C in the yarpdev terminal, it seems to always get stuck, and then I have to kill the yarpdev process. The last message was

[INFO] |yarp.dev.Drivers| [try 1 of 3] Trying to shut down /yarpdev/quit

After some debugging, I noticed that when the signal handler was setting the static flag "terminated" to true, it was also attempting to close immediately the terminator port. But the terminator port is receiving the termination message and some race condition seemed to occur on Windows.

If we avoid to set the terminated flag from the signal handler and instead we wait for the termination port to do its job, then yarpdev closes smoothly without issues.

cc @randaz81 @Nicogene @traversaro

S-Dafarra avatar Mar 29 '24 16:03 S-Dafarra

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would update the release notes by adding a file in doc/release/<target_branch>, based on your changes.

update-docs[bot] avatar Mar 29 '24 16:03 update-docs[bot]