Skip to content

Commit a9843ab

Browse files
committed
Fix for multiple threads
1 parent 086c343 commit a9843ab

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.net.URI;
3131
import java.time.Duration;
32+
import java.util.concurrent.atomic.AtomicBoolean;
3233
import java.util.Map;
3334
import java.util.ServiceLoader;
3435
import java.util.Set;
@@ -130,8 +131,8 @@ public abstract class Node implements HasReadyState, Routable {
130131
private final URI uri;
131132
private final Duration sessionTimeout;
132133
private final Route routes;
133-
protected boolean draining;
134-
protected boolean registered;
134+
protected final AtomicBoolean draining = new AtomicBoolean(false);
135+
protected final AtomicBoolean registered = new AtomicBoolean(false);
135136

136137
protected Node(
137138
Tracer tracer, NodeId id, URI uri, Secret registrationSecret, Duration sessionTimeout) {
@@ -272,15 +273,15 @@ public Duration getSessionTimeout() {
272273
}
273274

274275
public boolean isDraining() {
275-
return draining;
276+
return draining.get();
276277
}
277278

278279
public boolean isRegistered() {
279-
return registered;
280+
return registered.get();
280281
}
281282

282283
public void register() {
283-
registered = true;
284+
registered.set(true);
284285
}
285286

286287
public abstract void drain();

java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
public class NodeServer extends TemplateGridServerCommand {
7575

7676
private static final Logger LOG = Logger.getLogger(NodeServer.class.getName());
77-
private final AtomicBoolean nodeRegistered = new AtomicBoolean(false);
7877
private Node node;
7978
private EventBus bus;
8079
private final Thread shutdownHook =
@@ -147,7 +146,6 @@ protected Handlers createHandlers(Config config) {
147146
NodeAddedEvent.listener(
148147
nodeId -> {
149148
if (node.getId().equals(nodeId)) {
150-
nodeRegistered.set(true);
151149
node.register();
152150
LOG.info("Node has been added");
153151
}
@@ -238,7 +236,7 @@ public NettyServer start() {
238236
Failsafe.with(registrationPolicy)
239237
.run(
240238
() -> {
241-
if (nodeRegistered.get()) {
239+
if (node.isRegistered()) {
242240
throw new InterruptedException("Stopping registration thread.");
243241
}
244242
HealthCheck.Result check = node.getHealthCheck().check();

java/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public NodeStatus getStatus() {
415415
@Override
416416
public void drain() {
417417
events.fire(new NodeDrainStarted(getId()));
418-
draining = true;
418+
draining.set(true);
419419
}
420420

421421
@Override

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ public void drain() {
10151015
AttributeMap attributeMap = tracer.createAttributeMap();
10161016
attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(), getClass().getName());
10171017
bus.fire(new NodeDrainStarted(getId()));
1018-
draining = true;
1018+
draining.set(true);
10191019
// Ensure the pendingSessions counter will not be decremented by timed out sessions not
10201020
// included
10211021
// in the currentSessionCount and the NodeDrainComplete will be raised to early.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public void drain() {
295295
HttpResponse res = client.with(addSecret).execute(req);
296296

297297
if (res.getStatus() == HTTP_OK) {
298-
draining = true;
298+
draining.set(true);
299299
}
300300
}
301301

0 commit comments

Comments
 (0)