Skip to content

Commit 9f664c6

Browse files
committed
[grid] check session ownership once
1 parent 71bc491 commit 9f664c6

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

java/src/org/openqa/selenium/grid/node/ForwardWebDriverCommand.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
package org.openqa.selenium.grid.node;
1919

20-
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
20+
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
2121
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
2222
import static org.openqa.selenium.remote.http.Contents.asJson;
2323

24-
import com.google.common.collect.ImmutableMap;
24+
import java.util.Map;
2525
import org.openqa.selenium.internal.Require;
2626
import org.openqa.selenium.remote.SessionId;
2727
import org.openqa.selenium.remote.http.HttpHandler;
@@ -48,10 +48,16 @@ public HttpResponse execute(HttpRequest req) {
4848
return node.executeWebDriverCommand(req);
4949
}
5050
return new HttpResponse()
51-
.setStatus(HTTP_INTERNAL_ERROR)
51+
.setStatus(HTTP_NOT_FOUND)
5252
.setContent(
5353
asJson(
54-
ImmutableMap.of(
55-
"error", String.format("Session not found in node %s", node.getId()))));
54+
Map.of(
55+
"value",
56+
Map.of(
57+
"error", "invalid session id",
58+
"message",
59+
"Cannot find session with id: "
60+
+ getSessionId(req.getUri()).orElse(null),
61+
"stacktrace", ""))));
5662
}
5763
}

java/src/org/openqa/selenium/grid/node/Node.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,7 @@ protected Node(
154154
combine(
155155
// "getSessionId" is aggressive about finding session ids, so this needs to be the last
156156
// route that is checked.
157-
matching(
158-
req ->
159-
getSessionId(req.getUri())
160-
.map(SessionId::new)
161-
.map(sessionId -> this.getSession(sessionId) != null)
162-
.orElse(false))
157+
matching(req -> getSessionId(req.getUri()).map(SessionId::new).isPresent())
163158
.to(() -> new ForwardWebDriverCommand(this))
164159
.with(spanDecorator("node.forward_command")),
165160
new CustomLocatorHandler(this, registrationSecret, customLocators),

java/test/org/openqa/selenium/grid/router/StressTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public void setupServers() {
7777
+ "\n"
7878
+ "session-timeout = 11"
7979
+ "\n"
80+
+ "overwrite-max-sessions = true"
81+
+ "\n"
82+
+ "max-sessions = "
83+
+ Runtime.getRuntime().availableProcessors() * 2
84+
+ "\n"
8085
+ "enable-managed-downloads = true")));
8186
tearDowns.add(deployment);
8287

0 commit comments

Comments
 (0)