Skip to content

Commit

Permalink
[grid] avoid starting a session which will be disposed after start
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Nov 20, 2024
1 parent fefdba1 commit 192b2d5
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ public boolean retryAddToQueue(SessionRequest request) {
// return true to avoid handleNewSessionRequest to call 'complete' an other time
return true;
} else if (data.isCanceled()) {
complete(
request.getRequestId(),
Either.left(new SessionNotCreatedException("Client has gone away")));
failDueToCanceled(request.getRequestId());
// return true to avoid handleNewSessionRequest to call 'complete' an other time
return true;
}
Expand Down Expand Up @@ -370,7 +368,18 @@ public List<SessionRequest> getNextAvailable(Map<Capabilities, Long> stereotypes
.limit(batchSize)
.collect(Collectors.toList());

availableRequests.forEach(req -> this.remove(req.getRequestId()));
availableRequests.removeIf(
(req) -> {
Data data = this.requests.get(req.getRequestId());

if (data.isCanceled()) {
failDueToCanceled(req.getRequestId());
return true;
}

this.remove(req.getRequestId());
return false;
});

return availableRequests;
} finally {
Expand Down Expand Up @@ -458,6 +467,11 @@ private void failDueToTimeout(RequestId reqId) {
complete(reqId, Either.left(new SessionNotCreatedException("Timed out creating session")));
}

private void failDueToCanceled(RequestId reqId) {
// this error should never reach the client, as this is a client initiated state
complete(reqId, Either.left(new SessionNotCreatedException("Client has gone away")));
}

private class Data {

public final Instant endTime;
Expand Down

0 comments on commit 192b2d5

Please sign in to comment.