Skip to content

Fix subtle concurrency bugs in ddsrt_init(), ddsrt_fini()#2299

Open
mvandenhoek wants to merge 1 commit intoeclipse-cyclonedds:masterfrom
mvandenhoek:fix_ddsrt_init_fini
Open

Fix subtle concurrency bugs in ddsrt_init(), ddsrt_fini()#2299
mvandenhoek wants to merge 1 commit intoeclipse-cyclonedds:masterfrom
mvandenhoek:fix_ddsrt_init_fini

Conversation

@mvandenhoek
Copy link
Copy Markdown
Contributor

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:

  • Remove the retry logic to avoid extra increments that mess with the refcount balance
  • Correctly handle concurrent calls to ddsrt_init() and ddsrt_fini()

Signed-off-by: Michel van den Hoek <michel.vandenhoek@zettascale.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant