Repository navigation
fix(api): log and metrics reads hold no account lock or transaction while the store answers (closes #488) - #509
Merged
Conversation
…hile the store answers (closes #488) Each read ran inside the account mutation authority, so a slow VictoriaLogs or VictoriaMetrics held the account's row lock and a database transaction for up to its timeout. Access is now checked in a short transaction, the store is read outside any, and access is checked again before anything is returned: access lost during the read returns nothing. Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 14 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
What changed
LogsQueries.searchandMetricsQueries.application,nodeandorganizationnow split each read into three steps:AccountMutationAuthority.run: account, API token scope, permission, and the resource's existence. This is a short transaction under the account's lock.For the organization chart, the second check also requires that every environment the read covered is still readable. If one is not, the read is refused with the usual 404, rather than returning series the person may no longer read.
SPEC 12 (logs and metrics) states the rule.
Why
Closes #488. Each read ran inside the authority's
withUserLock, which holds the account's row withSELECT … FOR UPDATEand a database transaction for the whole callback. A slow VictoriaLogs or VictoriaMetrics, up to its 10 s timeout, held that lock and a pooled connection. It delayed every other operation of that account, password resets and permission changes included. It also broke the unit of work's rule that network I/O happens outside a transaction.How it was tested
logs-lock.integration.spec.ts(new): real HTTP pipeline and PostgreSQL, with the log store replaced by a fake that waits.pg_stat_activityshows noidle in transactionconnection, and a project creation by the same owner, which takes the account's lock, answers 201.idle in transaction, and the viewer gets 200 with the line.logs-queries.spec.tsandmetrics-queries.spec.ts:api:lintandapi:typecheck.Security considerations
The second check is the same one as the first, so an API token revoked, an account disabled or a role removed during the read returns nothing. Tenant filtering, response bounds and the store's sanitized 503 errors are unchanged. Upstream timeouts and oversized answers are still handled by the stores, whose code is unchanged.