OTel: fix problematic Timeout class usages#10789
Open
Conversation
According to the Asio docs [^1], `Strand::running_in_this_thread()` returns `true` only if the current thread is executing a handler that was posted (boost::asio::post()), dispatched (boost::asio::dispatch()), or deferred (boost::asio::defer()) through the strand. In all other cases, it returns `false` causing to crash Icinga 2 when trying to use the `Timeout` class in `OTel` after a coroutine is resumed that was waiting on a timer via `async_wait()`. Interestingly, the crash only happens when building Icinga 2 in release mode, in debug mode it works just fine. So, it seems that the behavior of `Strand::running_in_this_thread()` is different in release and debug modes, which could be due to compiler or Asio's own optimizations. [^1]: https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/reference/strand/running_in_this_thread.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
According to the Asio docs 1,
Strand::running_in_this_thread()returnstrueonly if the current thread is executing a handler that was posted (boost::asio::post()), dispatched (boost::asio::dispatch()), or deferred (boost::asio::defer()) through the strand. In all other cases, it returnsfalsecausing to crash Icinga 2 when trying to use theTimeoutclass inOTelafter a coroutine is resumed that was waiting on a timer viaasync_wait(). Interestingly, the crash only happens when building Icinga 2 in release mode, in debug mode it works just fine. So, it seems that the behavior ofStrand::running_in_this_thread()is different in release and debug modes, which could be due to compiler or Asio's own optimizations.The fix is simple: remove the assertion completely because it is not necessary anyway as it's not a requirement for the
Timeoutclass to work correctly. Even ifstrand::running_in_this_thread()returnsfalse, it doesn't necessarily mean that the strand is not being used correctly, so the assertion is not a reliable way to check for correct usage of the strand.To verify the bug, you can apply the following patch to the
OTelclass:Crush Dumps
fixes #10783
Footnotes
https://www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/reference/strand/running_in_this_thread.html ↩