Skip to content

Commit e3d3da3

Browse files
committed
[grid] Standalone should also shutdown when it has been drained
1 parent a78b998 commit e3d3da3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎java/src/org/openqa/selenium/grid/commands/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ java_library(
2020
"//java/src/org/openqa/selenium/events",
2121
"//java/src/org/openqa/selenium/grid:base-command",
2222
"//java/src/org/openqa/selenium/grid/config",
23+
"//java/src/org/openqa/selenium/grid/data",
2324
"//java/src/org/openqa/selenium/grid/distributor",
2425
"//java/src/org/openqa/selenium/grid/distributor/config",
2526
"//java/src/org/openqa/selenium/grid/distributor/local",

‎java/src/org/openqa/selenium/grid/commands/Standalone.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.openqa.selenium.grid.TemplateGridServerCommand;
2828
import org.openqa.selenium.grid.config.Config;
2929
import org.openqa.selenium.grid.config.Role;
30+
import org.openqa.selenium.grid.data.NodeDrainComplete;
3031
import org.openqa.selenium.grid.distributor.Distributor;
3132
import org.openqa.selenium.grid.distributor.config.DistributorOptions;
3233
import org.openqa.selenium.grid.distributor.local.LocalDistributor;
@@ -204,6 +205,27 @@ protected Handlers createHandlers(Config config) {
204205
combinedHandler.addHandler(node);
205206
distributor.add(node);
206207

208+
bus.addListener(NodeDrainComplete.listener(nodeId -> {
209+
if (!node.getId().equals(nodeId)) {
210+
return;
211+
}
212+
213+
// Wait a beat before shutting down so the final response from the
214+
// node can escape.
215+
new Thread(
216+
() -> {
217+
try {
218+
Thread.sleep(1000);
219+
} catch (InterruptedException e) {
220+
// Swallow, the next thing we're doing is shutting down
221+
}
222+
LOG.info("Shutting down");
223+
System.exit(0);
224+
},
225+
"Standalone shutdown: " + nodeId)
226+
.start();
227+
}));
228+
207229
return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node));
208230
}
209231

0 commit comments

Comments
 (0)