Skip to content

Commit 4cd7f10

Browse files
Merge pull request #54229 from bernhardoj/chore/update-comment
[No QA] Update comment followup from 54110
2 parents f593c21 + 010c488 commit 4cd7f10

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/libs/Network/SequentialQueue.ts

+11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ function process(): Promise<void> {
128128
return currentRequestPromise;
129129
}
130130

131+
/**
132+
* @param shouldResetPromise Determines whether the isReadyPromise should be reset.
133+
* A READ request will wait until all the WRITE requests are done, using the isReadyPromise promise.
134+
* Resetting can cause unresolved READ requests to hang if tied to the old promise,
135+
* so some cases (e.g., unpausing) require skipping the reset to maintain proper behavior.
136+
*/
131137
function flush(shouldResetPromise = true) {
132138
// 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
133139
if (isQueuePaused) {
@@ -198,6 +204,11 @@ function unpause() {
198204
const numberOfPersistedRequests = PersistedRequests.getAll().length || 0;
199205
Log.info(`[SequentialQueue] Unpausing the queue and flushing ${numberOfPersistedRequests} requests`);
200206
isQueuePaused = false;
207+
208+
// When the queue is paused and then unpaused, we call flush which by defaults recreates the isReadyPromise.
209+
// After all the WRITE requests are done, the isReadyPromise is resolved, but since it's a new instance of promise,
210+
// the pending READ request never received the resolved callback. That's why we don't want to recreate
211+
// the promise when unpausing the queue.
201212
flush(false);
202213
}
203214

tests/unit/APITest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ describe('APITests', () => {
581581
});
582582
});
583583

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

0 commit comments

Comments
 (0)