@@ -152,13 +152,9 @@ export class ClusterAwareReaderFailoverHandler implements ReaderFailoverHandler
152
152
return result ;
153
153
}
154
154
} catch ( error ) {
155
- if ( error instanceof AggregateError && error . message . includes ( "All promises were rejected" ) ) {
156
- // ignore and try the next batch
157
- } else {
158
- // Failover has failed.
159
- this . taskHandler . setSelectedConnectionAttemptTask ( failoverTaskId , ClusterAwareReaderFailoverHandler . FAILOVER_FAILED ) ;
160
- throw error ;
161
- }
155
+ // Failover has failed.
156
+ this . taskHandler . setSelectedConnectionAttemptTask ( failoverTaskId , ClusterAwareReaderFailoverHandler . FAILOVER_FAILED ) ;
157
+ throw error ;
162
158
}
163
159
164
160
await sleep ( 1000 ) ;
@@ -184,7 +180,7 @@ export class ClusterAwareReaderFailoverHandler implements ReaderFailoverHandler
184
180
throw new AwsWrapperError ( "Connection attempt task timed out." ) ;
185
181
} )
186
182
. catch ( ( error ) => {
187
- if ( error instanceof InternalQueryTimeoutError || ( error instanceof AggregateError && error . message . includes ( "All promises were rejected" ) ) ) {
183
+ if ( error instanceof InternalQueryTimeoutError ) {
188
184
// ignore so the next task batch can be attempted
189
185
return ClusterAwareReaderFailoverHandler . FAILED_READER_FAILOVER_RESULT ;
190
186
}
@@ -207,7 +203,26 @@ export class ClusterAwareReaderFailoverHandler implements ReaderFailoverHandler
207
203
tasks . push ( secondTask . call ( ) ) ;
208
204
}
209
205
210
- return await Promise . any ( tasks ) ;
206
+ return await Promise . any ( tasks ) . catch ( ( error : AggregateError ) => {
207
+ let errors : string = "" ;
208
+ for ( const e of error . errors ) {
209
+ // Propagate errors that are not caused by network errors.
210
+ if ( ! this . pluginService . isNetworkError ( error ) ) {
211
+ errors += `\n\t${ e } - ${ e . message } ` ;
212
+ }
213
+ }
214
+ if ( errors ) {
215
+ const awsWrapperError = new AwsWrapperError (
216
+ Messages . get (
217
+ "ClusterAwareReaderFailoverHandler.batchFailed" ,
218
+ `[${ hosts [ i ] . hostId } ${ numTasks === 2 ? `, ${ hosts [ i + 1 ] . hostId } ` : `` } ]` ,
219
+ `[\n${ errors } \n]`
220
+ )
221
+ ) ;
222
+ return new ReaderFailoverResult ( null , null , false , awsWrapperError ) ;
223
+ }
224
+ return new ReaderFailoverResult ( null , null , false , undefined ) ;
225
+ } ) ;
211
226
}
212
227
213
228
getReaderHostsByPriority ( hosts : HostInfo [ ] ) : HostInfo [ ] {
@@ -321,18 +336,9 @@ class ConnectionAttemptTask {
321
336
this . taskHandler . setSelectedConnectionAttemptTask ( this . failoverTaskId , this . taskId ) ;
322
337
return new ReaderFailoverResult ( this . targetClient , this . newHost , true , undefined , this . taskId ) ;
323
338
}
324
- await this . pluginService . abortTargetClient ( this . targetClient ) ;
325
- return new ReaderFailoverResult ( null , null , false , undefined , this . taskId ) ;
339
+ throw new AwsWrapperError ( Messages . get ( "ClusterAwareReaderFailoverHandler.selectedTaskChosen" , this . newHost . host ) ) ;
326
340
} catch ( error ) {
327
341
this . pluginService . setAvailability ( this . newHost . allAliases , HostAvailability . NOT_AVAILABLE ) ;
328
- if ( error instanceof Error ) {
329
- // Propagate errors that are not caused by network errors.
330
- if ( ! this . pluginService . isNetworkError ( error ) ) {
331
- return new ReaderFailoverResult ( null , null , false , error , this . taskId ) ;
332
- }
333
-
334
- return new ReaderFailoverResult ( null , null , false , undefined , this . taskId ) ;
335
- }
336
342
throw error ;
337
343
} finally {
338
344
await this . performFinalCleanup ( ) ;
0 commit comments