@@ -300,9 +300,7 @@ public boolean retryAddToQueue(SessionRequest request) {
300
300
// return true to avoid handleNewSessionRequest to call 'complete' an other time
301
301
return true ;
302
302
} else if (data .isCanceled ()) {
303
- complete (
304
- request .getRequestId (),
305
- Either .left (new SessionNotCreatedException ("Client has gone away" )));
303
+ failDueToCanceled (request .getRequestId ());
306
304
// return true to avoid handleNewSessionRequest to call 'complete' an other time
307
305
return true ;
308
306
}
@@ -370,7 +368,18 @@ public List<SessionRequest> getNextAvailable(Map<Capabilities, Long> stereotypes
370
368
.limit (batchSize )
371
369
.collect (Collectors .toList ());
372
370
373
- availableRequests .forEach (req -> this .remove (req .getRequestId ()));
371
+ availableRequests .removeIf (
372
+ (req ) -> {
373
+ Data data = this .requests .get (req .getRequestId ());
374
+
375
+ if (data .isCanceled ()) {
376
+ failDueToCanceled (req .getRequestId ());
377
+ return true ;
378
+ }
379
+
380
+ this .remove (req .getRequestId ());
381
+ return false ;
382
+ });
374
383
375
384
return availableRequests ;
376
385
} finally {
@@ -458,6 +467,11 @@ private void failDueToTimeout(RequestId reqId) {
458
467
complete (reqId , Either .left (new SessionNotCreatedException ("Timed out creating session" )));
459
468
}
460
469
470
+ private void failDueToCanceled (RequestId reqId ) {
471
+ // this error should never reach the client, as this is a client initiated state
472
+ complete (reqId , Either .left (new SessionNotCreatedException ("Client has gone away" )));
473
+ }
474
+
461
475
private class Data {
462
476
463
477
public final Instant endTime ;
0 commit comments