Fix subtle concurrency bugs in ddsrt_init(), ddsrt_fini()#2299
Open
mvandenhoek wants to merge 1 commit intoeclipse-cyclonedds:masterfrom
Open
Fix subtle concurrency bugs in ddsrt_init(), ddsrt_fini()#2299mvandenhoek wants to merge 1 commit intoeclipse-cyclonedds:masterfrom
mvandenhoek wants to merge 1 commit intoeclipse-cyclonedds:masterfrom
Conversation
3bf66e5 to
74cb5a2
Compare
Signed-off-by: Michel van den Hoek <michel.vandenhoek@zettascale.tech>
74cb5a2 to
138b87d
Compare
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.
This fixes subtle concurrency bugs in ddsrt_init() and ddsrt_fini().
The first problem is that ddsrt_init() has a ‘goto retry_init’ which results in the refcount being incremented more than once, which means that with balanced ddsrt_init() and ddsrt_fini() calls, the actual finalization will never be done. This happens even if you strictly orchestrate the threads such that the first ddsrt_fini() will only happen after all calls to ddsrt_init() have completed, so that ddsrt_init() and ddsrt_fini() are never called concurrently with one another.
The second problem occurs when ddsrt_init() and ddsrt_fini() are called concurrently. When the last ddsrt_fini() call happens, concurrent ddsrt_init() calls will end up being blocked indefinitely, so the program just hangs.
My fix solves both problems: