fix(chat): drain queue entries enqueued during lock release - #929
Open
salmundani wants to merge 1 commit into
Open
salmundani wants to merge 1 commit into
salmundani wants to merge 1 commit into
Conversation
Signed-off-by: Daniel Salmun <salmundani@gmail.com>
Author
|
By the way, exposing the class's internal synchronization primitives isn't usually the best idea (check "Java Concurrency in Practice" for practical examples). The bug I fixed is probably still latent in the failure paths of the code. Redesigning the StateAdapter so it has the following methods would be much cleaner in the long term. export interface StateAdapter {
// Everything above stays. The drop strategy and the fallback still use it.
/**
* Atomically: take the lock if it is free, otherwise add the entry to the
* queue. When `enqueueOnClaim` is true, the entry is also queued on claim,
* which debounce and burst need.
*/
claimOrEnqueue?(
threadId: string,
entry: QueueEntry,
options: {
ttlMs: number;
maxSize: number;
onQueueFull: "drop-oldest" | "drop-newest";
enqueueOnClaim: boole
}
): Promise<ClaimResult>;
/**
* Atomically and token-checked: pop all pending entries, or release the
* lock if the queue is e token no longer holds
* the lock, and then pop
*/
takeOrRelease?(lock: Lock): Promise<TakeResult>;
}
export type ClaimResult =
| { status: "claimed"; lock: Lock }
| { status: "queued"; dep
| { status: "dropped"; depth: number };
export type TakeResult =
| { status: "taken"; entries: QueueEntry[] }
| { status: "released" }
| { status: "lost" };Similar to the atomic These new methods should be optional as to not break 3rd party adapters, or otherwise be part of a major release. |
This branch has not been deployed
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.
Summary
Fixes #928
Test plan
Six new tests added that fail in the old code and pass with the fix.
pnpm validatealso passesChecklist
git commit -s)pnpm validatepasses