File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments