Skip to content

Commit a42e7b8

Browse files
committed
[grid] One instance of DriverService.Builder per Node Slot
1 parent 3b41e60 commit a42e7b8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

java/server/src/org/openqa/selenium/grid/node/local/LocalNodeFactory.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.grid.node.local;
1919

2020
import com.google.common.collect.ImmutableList;
21+
2122
import org.openqa.selenium.Capabilities;
2223
import org.openqa.selenium.grid.config.Config;
2324
import org.openqa.selenium.grid.data.DefaultSlotMatcher;
@@ -91,7 +92,18 @@ private static Collection<SessionFactory> createSessionFactory(
9192
builders.stream()
9293
.filter(builder -> builder.score(stereotype) > 0)
9394
.forEach(builder -> {
94-
DriverService.Builder<?, ?> driverServiceBuilder = builder.usingAnyFreePort();
95+
DriverService.Builder<?, ?> driverServiceBuilder;
96+
Class<?> clazz = builder.getClass();
97+
try {
98+
// We do this to give each Node slot its own instance of the DriverService.Builder.
99+
// This is important because the Node processes many new session requests
100+
// and the DriverService creation needs to be thread safe.
101+
Object driverBuilder = clazz.newInstance();
102+
driverServiceBuilder = ((DriverService.Builder<?, ?>) driverBuilder).usingAnyFreePort();
103+
} catch (InstantiationException | IllegalAccessException e) {
104+
throw new IllegalArgumentException(String.format(
105+
"Class %s could not be found or instantiated", clazz));
106+
}
95107
toReturn.add(new DriverServiceSessionFactory(
96108
tracer,
97109
clientFactory,

0 commit comments

Comments
 (0)