Skip to content

Commit 9af4e15

Browse files
committed
[grid] stop polling events on close
1 parent 9ff0f85 commit 9af4e15

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

java/src/org/openqa/selenium/concurrent/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ java_library(
44
name = "concurrent",
55
srcs = glob(["*.java"]),
66
visibility = [
7+
"//java/src/org/openqa/selenium/events:__subpackages__",
78
"//java/src/org/openqa/selenium/grid:__subpackages__",
89
"//java/src/org/openqa/selenium/remote:__subpackages__",
910
],

java/src/org/openqa/selenium/events/zeromq/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ java_library(
1212
],
1313
deps = [
1414
"//java/src/org/openqa/selenium:core",
15+
"//java/src/org/openqa/selenium/concurrent",
1516
"//java/src/org/openqa/selenium/events",
1617
"//java/src/org/openqa/selenium/grid/config",
1718
"//java/src/org/openqa/selenium/grid/security",

java/src/org/openqa/selenium/events/zeromq/UnboundZmqEventBus.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.function.Consumer;
4343
import java.util.logging.Level;
4444
import java.util.logging.Logger;
45+
import org.openqa.selenium.concurrent.ExecutorServices;
4546
import org.openqa.selenium.events.Event;
4647
import org.openqa.selenium.events.EventBus;
4748
import org.openqa.selenium.events.EventListener;
@@ -61,6 +62,7 @@ class UnboundZmqEventBus implements EventBus {
6162
private static final Logger LOG = Logger.getLogger(EventBus.class.getName());
6263
private static final Json JSON = new Json();
6364
private final AtomicBoolean pollingStarted = new AtomicBoolean(false);
65+
private final PollingRunnable socketPolling;
6466
private final ExecutorService socketPollingExecutor;
6567
private final ExecutorService socketPublishingExecutor;
6668
private final ExecutorService listenerNotificationExecutor;
@@ -147,7 +149,8 @@ class UnboundZmqEventBus implements EventBus {
147149

148150
LOG.info("Sockets created");
149151

150-
socketPollingExecutor.submit(new PollingRunnable(secret));
152+
socketPolling = new PollingRunnable(secret);
153+
socketPollingExecutor.submit(socketPolling);
151154

152155
// Give ourselves up to a second to connect, using The World's Worst heuristic. If we don't
153156
// manage to connect, it's not the end of the world, as the socket we're connecting to may not
@@ -211,9 +214,11 @@ public void fire(Event event) {
211214

212215
@Override
213216
public void close() {
214-
socketPollingExecutor.shutdownNow();
215-
socketPublishingExecutor.shutdownNow();
216-
listenerNotificationExecutor.shutdownNow();
217+
socketPolling.shutdown = true;
218+
ExecutorServices.shutdownGracefully("Event Bus Poller", socketPollingExecutor);
219+
ExecutorServices.shutdownGracefully("Event Bus Publisher", socketPublishingExecutor);
220+
ExecutorServices.shutdownGracefully(
221+
"Event Bus Listener Notifier", listenerNotificationExecutor);
217222
poller.close();
218223

219224
if (sub != null) {
@@ -226,14 +231,15 @@ public void close() {
226231

227232
private class PollingRunnable implements Runnable {
228233
private final Secret secret;
234+
private volatile boolean shutdown;
229235

230236
public PollingRunnable(Secret secret) {
231237
this.secret = secret;
232238
}
233239

234240
@Override
235241
public void run() {
236-
while (!Thread.currentThread().isInterrupted()) {
242+
while (!Thread.currentThread().isInterrupted() && !shutdown) {
237243
try {
238244
int count = poller.poll(150);
239245

0 commit comments

Comments
 (0)