Skip to content

Commit d8fb1d3

Browse files
Merge branch 'trunk' into null-exceptions
2 parents e2d0d7c + e4ab299 commit d8fb1d3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

java/src/org/openqa/selenium/grid/node/remote/RemoteNode.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.openqa.selenium.NoSuchSessionException;
4747
import org.openqa.selenium.RetrySessionRequestException;
4848
import org.openqa.selenium.SessionNotCreatedException;
49+
import org.openqa.selenium.TimeoutException;
4950
import org.openqa.selenium.WebDriverException;
5051
import org.openqa.selenium.grid.data.CreateSessionRequest;
5152
import org.openqa.selenium.grid.data.CreateSessionResponse;
@@ -132,7 +133,16 @@ public Either<WebDriverException, CreateSessionResponse> newSession(
132133
HttpTracing.inject(tracer, tracer.getCurrentContext(), req);
133134
req.setContent(asJson(sessionRequest));
134135

135-
HttpResponse httpResponse = client.with(addSecret).execute(req);
136+
HttpResponse httpResponse;
137+
try {
138+
httpResponse = client.with(addSecret).execute(req);
139+
} catch (TimeoutException e) {
140+
// When using a short session timeout the node might not be able to start the session in time.
141+
// The client timeout might be higher so, it makes sense to retry. In case the client does
142+
// timeout, the SessionRequest is marked as canceled and the session is either not added to
143+
// the queue or disposed as soon as the node started it.
144+
return Either.left(new RetrySessionRequestException("Timeout while starting the session", e));
145+
}
136146

137147
Optional<Map<String, Object>> maybeResponse =
138148
Optional.ofNullable(Values.get(httpResponse, Map.class));

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,18 @@ public boolean retryAddToQueue(SessionRequest request) {
293293
if (!requests.containsKey(request.getRequestId())) {
294294
return false;
295295
}
296-
if (isTimedOut(Instant.now(), requests.get(request.getRequestId()))) {
296+
Data data = requests.get(request.getRequestId());
297+
if (isTimedOut(Instant.now(), data)) {
297298
// as we try to re-add a session request that has already expired, force session timeout
298299
failDueToTimeout(request.getRequestId());
299300
// return true to avoid handleNewSessionRequest to call 'complete' an other time
300301
return true;
302+
} else if (data.isCanceled()) {
303+
complete(
304+
request.getRequestId(),
305+
Either.left(new SessionNotCreatedException("Client has gone away")));
306+
// return true to avoid handleNewSessionRequest to call 'complete' an other time
307+
return true;
301308
}
302309

303310
if (queue.contains(request)) {
@@ -472,6 +479,10 @@ public synchronized void cancel() {
472479
canceled = true;
473480
}
474481

482+
public synchronized boolean isCanceled() {
483+
return canceled;
484+
}
485+
475486
public synchronized boolean setResult(
476487
Either<SessionNotCreatedException, CreateSessionResponse> result) {
477488
if (complete || canceled) {

0 commit comments

Comments
 (0)