Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a data race condition when a service is initially flushed multiple times in parallel #178

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

bwoebi
Copy link
Contributor

@bwoebi bwoebi commented Jun 14, 2023

get_app() could be executed twice, while the AppInstance is still building. Prevent that by creating a future around it.

Also refactor register_service_and_flush_queued_actions to be a bit simpler and safe to repeated/concurrent calls of it.

@bwoebi bwoebi requested review from a team as code owners June 14, 2023 11:30
@bwoebi bwoebi force-pushed the bob/fix-sidecar-data-race branch 2 times, most recently from cdbe17a to 5391944 Compare June 14, 2023 11:35
…e times in parallel

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
@bwoebi bwoebi force-pushed the bob/fix-sidecar-data-race branch from 5391944 to 2b49578 Compare June 14, 2023 11:38
Copy link
Contributor

@paullegranddc paullegranddc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks ok too me.
Although main thing this achieve is the ability to lock a single key in the hashmap, and I feel like we should be able to find a cleaner pattern to write this because the code is pretty hard to reason about, but we can fix that latter.

@bwoebi bwoebi merged commit be650b7 into main Jun 14, 2023
@bwoebi
Copy link
Contributor Author

bwoebi commented Jun 14, 2023

Yes, it's essentially a lock, but I'm not sure how to express this in simpler terms, a read/write sync-safe lock could do it too probably, but coming from an async world, this pattern is fairly standard to me.

@bwoebi bwoebi deleted the bob/fix-sidecar-data-race branch June 14, 2023 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants