Skip to content

Commit 171cb28

Browse files
Make docker stop timeout configurable via STOP_TIMEOUT property
The --time argument to `docker stop` was previously hardcoded and could not be adjusted for containers that need more time to shut down gracefully. Modern Docker has also deprecated --time in favour of --timeout. Add a static STOP_TIMEOUT field consistent with the existing CLIENT_TIMEOUT and SKIP_RM_ON_STOP fields, and switch from the deprecated --time flag to --timeout. The value can be overridden via the system property: org.jenkinsci.plugins.docker.workflow.client.DockerClient.STOP_TIMEOUT or mutated from a Groovy init script at runtime. Fixes #733 Related to #719
1 parent 3e04e4f commit 171cb28

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public class DockerClient {
8686
@Restricted(NoExternalUse.class)
8787
public static boolean SKIP_RM_ON_STOP = Boolean.getBoolean(DockerClient.class.getName() + ".SKIP_RM_ON_STOP");
8888

89+
/**
90+
* Number of seconds to wait for a container to stop gracefully before sending SIGKILL.
91+
*/
92+
@SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="mutable for scripts")
93+
@Restricted(NoExternalUse.class)
94+
public static int STOP_TIMEOUT = Integer.getInteger(DockerClient.class.getName() + ".STOP_TIMEOUT", 1);
95+
8996
// e.g. 2015-04-09T13:40:21.981801679Z
9097
public static final String DOCKER_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
9198

@@ -182,7 +189,7 @@ public List<String> listProcess(@NonNull EnvVars launchEnv, @NonNull String cont
182189
* @param containerId The container ID.
183190
*/
184191
public void stop(@NonNull EnvVars launchEnv, @NonNull String containerId) throws IOException, InterruptedException {
185-
LaunchResult result = launch(launchEnv, false, "stop", "--time=1", containerId);
192+
LaunchResult result = launch(launchEnv, false, "stop", "--timeout=" + STOP_TIMEOUT, containerId);
186193
if (result.getStatus() != 0) {
187194
throw new IOException(String.format("Failed to kill container '%s'.", containerId));
188195
}

0 commit comments

Comments
 (0)