-
Notifications
You must be signed in to change notification settings - Fork 255
Avoid LinkContext being destroyed when timer handlers execute #395
Conversation
There was a race condition on shutdown. If link timer handlers were queued for execution (with success error code), LinkContext could be destroyed in the meantime and handlers would access freed memory. This fix blocks destruction if handlers are outstanding, and handler check isOnline
…f it's on the executor strand
|
I think we definitely want to fix this, but not by idling in a destructor. We'll keep the PR open though until we have a different fix. These kinds of issues with Async C++ are getting pretty tiresome now that we're basing all our new tech on Rust with async/await. |
|
Yep, the PR was more to illustrate the problem and work as a band-aid for my fork. Fixing the root cause was a bit beyond me. I'll stay tuned, thanks. Rust Async sounds really cool btw. I'm definitely tired of dealing with lifetime issues in C++ async |
|
Yeah, async is really hard to get right. Rust makes it trivial. We have Modbus and DNP3 implemenation (with bindings for C, Java, and .NET Core) under development if you're interested in how it works: |
|
@neilstephens Can you try #407 and see if the issue was properly resolved? I went with a slightly different approach than your original PR. |
|
@neilstephens I don't think there's a race condition here. Everything (including the timer) is executed in an ASIO strand, which guarantees sequential execution. From my understanding, the issue was that the callback captured |
|
@emgre , The only thing that isn't executed on the strand is the destruction of the LinkContext. That's why there was the race in the first place. The problem wasn't that the handlers were executed after, but during, the destruction of the LinkContext. Cheers. |
|
Replaced with #435 |
There was a race condition on shutdown.
If link timer handlers were queued for execution (with success error code),
LinkContext could be destroyed in the meantime and handlers would access freed memory.
This fix blocks destruction if handlers are outstanding, and handler check isOnline