Skip to content

Commit 192b2d5

Browse files
committed
[grid] avoid starting a session which will be disposed after start
1 parent fefdba1 commit 192b2d5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ public boolean retryAddToQueue(SessionRequest request) {
300300
// return true to avoid handleNewSessionRequest to call 'complete' an other time
301301
return true;
302302
} else if (data.isCanceled()) {
303-
complete(
304-
request.getRequestId(),
305-
Either.left(new SessionNotCreatedException("Client has gone away")));
303+
failDueToCanceled(request.getRequestId());
306304
// return true to avoid handleNewSessionRequest to call 'complete' an other time
307305
return true;
308306
}
@@ -370,7 +368,18 @@ public List<SessionRequest> getNextAvailable(Map<Capabilities, Long> stereotypes
370368
.limit(batchSize)
371369
.collect(Collectors.toList());
372370

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+
});
374383

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

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+
461475
private class Data {
462476

463477
public final Instant endTime;

0 commit comments

Comments
 (0)