fix: suppress spurious 'api_token id=undefined not found' error on lastSeen flush#2349
Open
livepeer-tessa wants to merge 1 commit intomasterfrom
Open
fix: suppress spurious 'api_token id=undefined not found' error on lastSeen flush#2349livepeer-tessa wants to merge 1 commit intomasterfrom
livepeer-tessa wants to merge 1 commit intomasterfrom
Conversation
…stSeen flush
When table.update() is called with an array of SQL conditions (instead of
a plain id string), the error path in table.ts was constructing the
NotFoundError message using doc.id — but doc is the partial update payload
{lastSeen: ...} which has no id field, producing the misleading message:
api_token id=undefined not found
Two fixes:
1. tracking.ts: pass throwIfEmpty:false for lastSeen updates.
These are best-effort — the token may have been deleted between the
auth check and the 60s-deferred flush, so a no-op UPDATE is not an
error and shouldn't throw at all. This is the primary fix.
2. table.ts: when query is an array, use the id from the query context
(or '(unknown)') rather than doc.id, which is never set in this call
path. This prevents the misleading 'id=undefined' in any future error
messages from other callers of update() with array queries.
Fixes #761 in daydreamlive/scope (18 occurrences of this error on staging,
hourly for token 2f25c979-904f-4fce-b329-4174b54fdcbf).
Signed-off-by: livepeer-tessa <tessa@livepeer.org>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Problem
staging-livepeer-apihas been logging this error ~18 times in the last 12h, roughly every 30–60 min:Root cause: In
tracking.ts,flushLastSeen()callstable.update()with an array of SQL conditions (not a plain id string). When the UPDATE matches 0 rows andthrowIfEmpty=true(the default),table.tsconstructs the error message usingdoc.id— butdocis the partial update payload{ lastSeen: <timestamp> }with no id field, sodoc.idis alwaysundefined.The real UUID is correctly logged at the call site (visible in the log output), but the
NotFoundErrormessage itself readsid=undefined.The UPDATE returns 0 rows because the second condition in the WHERE clause:
...is false when the stored
lastSeenis already >= the value being flushed (race between multiple concurrent requests for the same token). This is expected/benign behaviour.Fix
Primary fix —
tracking.ts: Pass{ throwIfEmpty: false }totable.update()forlastSeenupdates. These are best-effort bookkeeping — a no-op UPDATE (token deleted, or lastSeen already up-to-date) is not an error and should not throw.Secondary fix —
table.ts: Whenqueryis an array, use the id from the query context ((doc as any).id ?? '(unknown)') rather thandoc.id, which is never populated in this call path. This prevents the misleadingid=undefinedin any future error messages from other callers ofupdate()with array queries.Impact
Closes daydreamlive/scope#761