Skip to content

Commit 0b56314

Browse files
committed
Fix missing sync lock in syncBlocks causing race conditions
1 parent c8104c9 commit 0b56314

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/platform/fabric/sync/SyncService.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ export class SyncServices {
381381
logger.info(`syncBlocks: Block sync in process for >> ${synch_key}`);
382382
return;
383383
}
384+
385+
// Acquire the sync lock
386+
this.synchInProcess.push(synch_key);
387+
384388
try {
385389
// Get channel information from ledger
386390
const channelInfo = await client.fabricGateway.queryChainInfo(channel_name);
@@ -477,11 +481,15 @@ export class SyncServices {
477481
} else {
478482
logger.debug('Missing blocks not found for %s', channel_name);
479483
}
480-
const index = this.synchInProcess.indexOf(synch_key);
481-
this.synchInProcess.splice(index, 1);
482484
logger.info(`syncBlocks: Finish >> ${synch_key}`);
483485
} catch (error) {
484486
logger.error(`Error in syncBlocks: ${error}`);
487+
} finally {
488+
// Release the sync lock - use guard to prevent array corruption from splice(-1, 1)
489+
const index = this.synchInProcess.indexOf(synch_key);
490+
if (index > -1) {
491+
this.synchInProcess.splice(index, 1);
492+
}
485493
}
486494
}
487495

0 commit comments

Comments
 (0)