Skip to content

Commit

Permalink
[grid] Simple flag to avoid stopping container twice [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Nov 12, 2020
1 parent e17affd commit cc5cf1b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions java/server/src/org/openqa/selenium/docker/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public class Container {
private static final Logger LOG = Logger.getLogger(Container.class.getName());
private final DockerProtocol protocol;
private final ContainerId id;
private boolean running;

public Container(DockerProtocol protocol, ContainerId id) {
this.protocol = Require.nonNull("Protocol", protocol);
this.id = Require.nonNull("Container id", id);
this.running = false;
LOG.info("Created container " + id);
}

Expand All @@ -42,16 +44,20 @@ public ContainerId getId() {
public void start() {
LOG.info("Starting " + getId());
protocol.startContainer(id);
this.running = true;
}

public void stop(Duration timeout) {
Require.nonNull("Timeout to wait for", timeout);

LOG.info("Stopping " + getId());
try {
protocol.stopContainer(id, timeout);
} catch (RuntimeException e) {
LOG.log(Level.WARNING, "Unable to stop container: " + e.getMessage(), e);
if (this.running) {
LOG.info("Stopping " + getId());
try {
protocol.stopContainer(id, timeout);
this.running = false;
} catch (RuntimeException e) {
LOG.log(Level.WARNING, "Unable to stop container: " + e.getMessage(), e);
}
}
}

Expand Down

0 comments on commit cc5cf1b

Please sign in to comment.