Conversation
Because: * recordAuthorizationRows upserted one accountAuthorizations row per scope via Promise.allSettled, opening N pooled DB connections for an N-scope sign-in and raising connection counts after the June 10 prod deploy. This commit: * Replaces the per-scope writes with one multi-row INSERT ... ON DUPLICATE KEY UPDATE built at call time, so every scope for a sign-in is recorded in a single query/connection. * Renames recordSignInConsent/_upsertAccountConsent to the plural recordSignInConsents/_upsertAccountConsents taking a scopes array. * Makes the write atomic (all rows land or none); a rejection bubbles to the existing authorizationHandler catch that emits write_failed and keeps sign-in working. * Types the route spec logger mock as createMock<AuthLogger>() and adds remote coverage for multi-scope row creation and timestamp bumping. Closes #FXA-14077
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.
Because
recordAuthorizationRowsupserted oneaccountAuthorizationsrow per requested scope viaPromise.allSettled, so an N-scope sign-in briefly held N pooled DB connections. This showed up as elevated OAuth DB connection counts after the June 10 prod deploy (FXA-14077).This pull request
INSERT ... ON DUPLICATE KEY UPDATE, built at call time in_upsertAccountConsents(packages/fxa-auth-server/lib/oauth/db/mysql/index.js), so every scope for a sign-in is recorded in one query/connection.recordSignInConsent/_upsertAccountConsentto the pluralrecordSignInConsents/_upsertAccountConsents, taking ascopesarray, inpackages/fxa-auth-server/lib/oauth/db/index.jsandauthorization.js.authorizationHandlercatch that emitsaccountAuthorization.write_failedand keeps sign-in working.createMock<AuthLogger>()and adds remote coverage intest/remote/account_consents.in.spec.tsfor multi-scope row creation andfirstAuthorizedTosAt/lastAuthorizedTosAtpreserve/bump behavior.Issue that this pull request solves
Closes: FXA-14077
Checklist
Put an
xin the boxes that applyHow to review (Optional)
lib/oauth/db/mysql/index.js(_upsertAccountConsentsquery construction),lib/routes/oauth/authorization.js(recordAuthorizationRowsfailure handling).VALUEStuple construction (only the tuple count is dynamic; all values are?-bound) and the non-emptyscopesinvariant, which holds becauserecordAuthorizationRowsreturns early when there are no requested scopes.Screenshots (Optional)
Please attach the screenshots of the changes made in case of change in user interface.
Other information (Optional)
Promise.allSettledpath could leave partial rows and surfaced only the first rejection; the single INSERT is now all-or-nothing.accountAuthorization.consents_write_failedstatsd/log event, but it was removed in favor of the existingwrite_failedhandler to avoid double-counting the same failure. Happy to reintroduce tagged detail in review if we want per-service/scope signal.