@@ -141,10 +141,13 @@ export class ChecksumCache {
141141 checkpoint : BigInt ( checkpoint )
142142 } ;
143143
144- // Individual cache fetch promises
145- let cacheFetchPromises : Promise < void > [ ] = [ ] ;
144+ // One promise to await to ensure all fetch requests completed.
145+ let settledPromise : Promise < PromiseSettledResult < void > [ ] > | null = null ;
146146
147147 try {
148+ // Individual cache fetch promises
149+ let cacheFetchPromises : Promise < void > [ ] = [ ] ;
150+
148151 for ( let bucket of buckets ) {
149152 const cacheKey = makeCacheKey ( checkpoint , bucket ) ;
150153 let status : LRUCache . Status < BucketChecksum > = { } ;
@@ -165,6 +168,9 @@ export class ChecksumCache {
165168 toFetch . add ( bucket ) ;
166169 }
167170 }
171+ // We do this directly after creating the promises, otherwise
172+ // we could end up with weird uncaught rejection errors.
173+ settledPromise = Promise . allSettled ( cacheFetchPromises ) ;
168174
169175 if ( toFetch . size == 0 ) {
170176 // Nothing to fetch, but resolve in case
@@ -251,12 +257,21 @@ export class ChecksumCache {
251257 rejectFetch ( e ) ;
252258
253259 // Wait for the above rejection to propagate, otherwise we end up with "uncaught" errors.
254- await Promise . all ( cacheFetchPromises ) . catch ( ( _e ) => { } ) ;
260+ // This promise never throws.
261+ await settledPromise ;
255262
256263 throw e ;
257264 }
258265
259- await Promise . all ( cacheFetchPromises ) ;
266+ // Wait for all cache fetch reqeusts to complete
267+ const settledResults = ( await settledPromise ) ?? [ ] ;
268+ // Check if any of them failed
269+ for ( let result of settledResults ) {
270+ if ( result . status == 'rejected' ) {
271+ throw result . reason ;
272+ }
273+ }
274+
260275 if ( finalResults . size != buckets . length ) {
261276 // Should not happen
262277 throw new Error ( `Bucket results mismatch: ${ finalResults . size } != ${ buckets . length } ` ) ;
0 commit comments