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

[No QA] Update comment followup from 54110 #54229

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/libs/Network/SequentialQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ function process(): Promise<void> {
return currentRequestPromise;
}

/**
* @param shouldResetPromise Determines whether the isReadyPromise should be reset.
* A READ request will wait until all the WRITE requests are done, using the isReadyPromise promise.
* Resetting can cause unresolved READ requests to hang if tied to the old promise,
* so some cases (e.g., unpausing) require skipping the reset to maintain proper behavior.
*/
function flush(shouldResetPromise = true) {
// When the queue is paused, return early. This will keep an requests in the queue and they will get flushed again when the queue is unpaused
if (isQueuePaused) {
Expand Down Expand Up @@ -198,6 +204,11 @@ function unpause() {
const numberOfPersistedRequests = PersistedRequests.getAll().length || 0;
Log.info(`[SequentialQueue] Unpausing the queue and flushing ${numberOfPersistedRequests} requests`);
isQueuePaused = false;

// When the queue is paused and then unpaused, we call flush which by defaults recreates the isReadyPromise.
// After all the WRITE requests are done, the isReadyPromise is resolved, but since it's a new instance of promise,
// the pending READ request never received the resolved callback. That's why we don't want to recreate
// the promise when unpausing the queue.
flush(false);
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/APITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ describe('APITests', () => {
});
});

test('Read request should not stuck when SequentialQueue is paused an resumed', async () => {
test('Read request should not stuck when SequentialQueue is paused and resumed', async () => {
// Given 2 WRITE requests and 1 READ request where the first write request pauses the SequentialQueue
const xhr = jest.spyOn(HttpUtils, 'xhr').mockResolvedValueOnce({previousUpdateID: 1});
API.write('MockWriteCommandOne' as WriteCommand, {});
Expand Down
Loading