Fix call home client thread cleanup#82
Merged
michalvasko merged 1 commit intoCESNET:develfrom Sep 13, 2018
Merged
Conversation
This commit by @thelsper fixes a race condition in call home client creation and deletion. If a call home client is deleted and then immediately re-created with the same client name, the old client thread will not notice that the old client was destroyed, and will attempt to service the new client, while the newly created client thread for the new client also attempts to service the new client! This results in a proliferation of threads and can also result in deadlock. To fix this, we added a unique client ID to the client information. When a client thread retrieves its client by name, it will now also check the client ID against the cached value of the client ID for the client it was previously servicing. If the client ID changes, this means that the client was destroyed, and the thread will clean itself up. While we were here making these changes we also changed the session ID to be a true atomic, and removed the spin lock that was protecting it. (The atomic operations library stdatomic.h was added in C11, which was why we also appended `-std=gnu11` to the `CFLAGS`. Both sysrepo and netopeer2 are already using C11.)
michalvasko
approved these changes
Sep 13, 2018
Member
|
Hi, Regards, |
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 commit by @thelsper fixes a race condition in call home client creation and deletion. If a call home client is deleted and then immediately re-created with the same client name, the old client thread will not notice that the old client was destroyed, and will attempt to service the new client, while the newly created client thread for the new client also attempts to service the new client! This results in a proliferation of threads and can also result in deadlock.
To fix this, we added a unique client ID to the client information. When a client thread retrieves its client by name, it will now also check the client ID against the cached value of the client ID for the client it was previously servicing. If the client ID changes, this means that the client was destroyed, and the thread will clean itself up.
While we were here making these changes we also changed the session ID to be a true atomic, and removed the spin lock that was protecting it. (stdatomic.h was added in C11, which was why we also appended
-std=gnu11to theCFLAGS. Both sysrepo and netopeer2 are already using C11.)