Skip to content

Commit b054bf1

Browse files
Add code comments
1 parent bf881fc commit b054bf1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,16 @@ The next upload iteration will be delayed.`);
449449
await this.streamingSyncIteration(nestedAbortController.signal, options);
450450
// Continue immediately, streamingSyncIteration will wait before completing if necessary.
451451
} catch (ex) {
452-
let delay = true;
453452
/**
454453
* Either:
455454
* - A network request failed with a failed connection or not OKAY response code.
456455
* - There was a sync processing error.
457-
* This loop will retry.
456+
* - The connection was aborted.
457+
* This loop will retry after a delay if the connection was not aborted.
458458
* The nested abort controller will cleanup any open network requests and streams.
459459
* The WebRemote should only abort pending fetch requests or close active Readable streams.
460460
*/
461+
let delay = true;
461462
if (ex instanceof AbortOperation) {
462463
this.logger.warn(ex);
463464
delay = false;

packages/web/src/worker/sync/SharedSyncImplementation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class SharedSyncImplementation
145145
await this.openInternalDB();
146146
}
147147

148-
const sync = await this.generateStreamingImplementation();
148+
const sync = this.generateStreamingImplementation();
149149
const onDispose = sync.registerListener({
150150
statusChanged: (status) => {
151151
this.updateAllStatuses(status.toJSON());
@@ -270,6 +270,9 @@ export class SharedSyncImplementation
270270
* clients.
271271
*/
272272
async removePort(port: MessagePort) {
273+
// Remove the port within a mutex context.
274+
// Warns if the port is not found. This should not happen in practice.
275+
// We return early if the port is not found.
273276
const { trackedPort, shouldReconnect } = await this.portMutex.runExclusive(async () => {
274277
const index = this.ports.findIndex((p) => p.port == port);
275278
if (index < 0) {

packages/web/tests/utils/MockStreamOpenFactory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class MockRemote extends AbstractRemote {
8181
if (this.errorOnStreamStart) {
8282
controller.error(new Error('Mock error on stream start'));
8383
}
84+
// The request could be aborted at any time.
85+
// This checks if the signal is already aborted and closes the stream if so.
86+
// If not, it adds an event listener to close the stream when the signal is aborted.
8487
if (signal?.aborted) {
8588
controller.close();
8689
return;

0 commit comments

Comments
 (0)