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

remoteconfig: fine grained locking #2458

Merged
merged 9 commits into from Jan 8, 2024
Merged

Conversation

Hellzy
Copy link
Contributor

@Hellzy Hellzy commented Dec 20, 2023

What does this PR do?

JIRA: APPSEC-18154

This adds a finer brand of locking to the remoteconfig client in order to allow using the exported API asynchronously.

  • Add RW mutex for products

  • Add RW mutex for capabilities

  • Add RW mutex for callbacks

  • Add RW mutex for productsWithCallback

  • Add async testing of public API

Motivation

The current implementation relies on a global lock in the entry point of the config update routine which means that
the client can't be used when it's receiving an update. This is a problem since callbacks are called during the update
routine, and those callbacks in turn may very well need to register new products/capabilities/callbacks. This leads to a possibility of deadlock.
Adding finer locking (1 mutex/data structure, basically) allows to modify the client's state during a configurations update and in turns makes it possible for callbacks to register capabilities, products, other callbacks, etc...

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@Hellzy Hellzy force-pushed the francois.mazeau/rc-lock-fix branch from e909608 to 53e5d7e Compare January 8, 2024 10:01
@Hellzy Hellzy marked this pull request as ready for review January 8, 2024 10:01
@Hellzy Hellzy requested a review from a team as a code owner January 8, 2024 10:01
@felixge
Copy link
Member

felixge commented Jan 8, 2024

Could you please add a description / motivation for this PR? Thanks!

@pr-commenter
Copy link

pr-commenter bot commented Jan 8, 2024

Benchmarks

Benchmark execution time: 2024-01-08 13:18:01

Comparing candidate commit 625415c in PR branch francois.mazeau/rc-lock-fix with baseline commit f76870b in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 39 metrics, 2 unstable metrics.

Comment on lines 94 to 99
_callbacksMu sync.RWMutex
products map[string]struct{}
_productsMu sync.RWMutex
productsWithCallbacks map[string]ProductCallback
capabilities map[Capability]struct{}
_capabilitiesMu sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is there any reason for prefixing these fields with underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a personal habit, I can remove the prefixes

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine. Let me review it again.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I think this sets a bad precedence. Using underscore prefixes for go variable names, especially on structs, is highly unorthodox. It'd be nice if we could not do this going forward.

@Hellzy Hellzy marked this pull request as draft January 8, 2024 10:24
@Hellzy Hellzy marked this pull request as ready for review January 8, 2024 10:45
@Hellzy Hellzy merged commit d28a899 into main Jan 8, 2024
153 checks passed
@Hellzy Hellzy deleted the francois.mazeau/rc-lock-fix branch January 8, 2024 13:56
Hellzy added a commit that referenced this pull request Jan 8, 2024
…figuration update (#2458)

A deadlock occurred when trying to modify the remote configuration client using its public API while a configuration update was happening. This was due to the global lock performed in the update goroutine.
This change introduces several new RWLocks for various data structures in order to avoid the global lock, and allow updating data in the client while the client is updating its configurations.
Hellzy added a commit that referenced this pull request Jan 8, 2024
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.

None yet

4 participants