Skip to content

Commit 62d24ff

Browse files
authored
Always close unconsumed InputStreams (docker-java#1290)
1 parent 9957bf7 commit 62d24ff

17 files changed

+112
-42
lines changed

docker-java-core/src/main/java/com/github/dockerjava/core/exec/ConnectToNetworkCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
88

9+
import java.io.IOException;
10+
911
public class ConnectToNetworkCmdExec extends AbstrSyncDockerCmdExec<ConnectToNetworkCmd, Void>
1012
implements ConnectToNetworkCmd.Exec {
1113

@@ -21,7 +23,11 @@ protected Void execute(ConnectToNetworkCmd command) {
2123
WebTarget webTarget = getBaseResource().path("/networks/" + command.getNetworkId() + "/connect");
2224

2325
LOGGER.trace("POST: {}", webTarget);
24-
webTarget.request().post(command);
26+
try {
27+
webTarget.request().post(command).close();
28+
} catch (IOException e) {
29+
throw new RuntimeException(e);
30+
}
2531

2632
return null;
2733
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/DisconnectFromNetworkCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
88

9+
import java.io.IOException;
10+
911
public class DisconnectFromNetworkCmdExec extends AbstrSyncDockerCmdExec<DisconnectFromNetworkCmd, Void>
1012
implements DisconnectFromNetworkCmd.Exec {
1113

@@ -21,7 +23,11 @@ protected Void execute(DisconnectFromNetworkCmd command) {
2123
WebTarget webTarget = getBaseResource().path("/networks/" + command.getNetworkId() + "/disconnect");
2224

2325
LOGGER.trace("POST: {}", webTarget);
24-
webTarget.request().post(command);
26+
try {
27+
webTarget.request().post(command).close();
28+
} catch (IOException e) {
29+
throw new RuntimeException(e);
30+
}
2531

2632
return null;
2733
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/InitializeSwarmCmdExec.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010

11+
import java.io.IOException;
12+
1113
public class InitializeSwarmCmdExec extends AbstrSyncDockerCmdExec<InitializeSwarmCmd, Void>
1214
implements InitializeSwarmCmd.Exec {
1315

@@ -22,8 +24,11 @@ protected Void execute(InitializeSwarmCmd command) {
2224
WebTarget webResource = getBaseResource().path("/swarm/init");
2325

2426
LOGGER.trace("POST: {} ", webResource);
25-
webResource.request().accept(MediaType.APPLICATION_JSON)
26-
.post(command);
27+
try {
28+
webResource.request().accept(MediaType.APPLICATION_JSON).post(command).close();
29+
} catch (IOException e) {
30+
throw new RuntimeException(e);
31+
}
2732
return null;
2833
}
2934
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/JoinSwarmCmdExec.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010

11+
import java.io.IOException;
12+
1113
public class JoinSwarmCmdExec extends AbstrSyncDockerCmdExec<JoinSwarmCmd, Void>
1214
implements JoinSwarmCmd.Exec {
1315

@@ -22,8 +24,11 @@ protected Void execute(JoinSwarmCmd command) {
2224
WebTarget webResource = getBaseResource().path("/swarm/join");
2325

2426
LOGGER.trace("POST: {} ", webResource);
25-
webResource.request().accept(MediaType.APPLICATION_JSON)
26-
.post(command);
27+
try {
28+
webResource.request().accept(MediaType.APPLICATION_JSON).post(command).close();
29+
} catch (IOException e) {
30+
throw new RuntimeException(e);
31+
}
2732
return null;
2833
}
2934
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/KillContainerCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.github.dockerjava.core.MediaType;
99
import com.github.dockerjava.core.WebTarget;
1010

11+
import java.io.IOException;
12+
1113
public class KillContainerCmdExec extends AbstrSyncDockerCmdExec<KillContainerCmd, Void> implements
1214
KillContainerCmd.Exec {
1315

@@ -27,7 +29,11 @@ protected Void execute(KillContainerCmd command) {
2729
}
2830

2931
LOGGER.trace("POST: {}", webResource);
30-
webResource.request().accept(MediaType.APPLICATION_JSON).post(null);
32+
try {
33+
webResource.request().accept(MediaType.APPLICATION_JSON).post(null).close();
34+
} catch (IOException e) {
35+
throw new RuntimeException(e);
36+
}
3137

3238
return null;
3339
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/LeaveSwarmCmdExec.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99

10+
import java.io.IOException;
11+
1012
public class LeaveSwarmCmdExec extends AbstrSyncDockerCmdExec<LeaveSwarmCmd, Void> implements LeaveSwarmCmd.Exec {
1113

1214
private static final Logger LOGGER = LoggerFactory.getLogger(LeaveSwarmCmdExec.class);
@@ -22,8 +24,11 @@ protected Void execute(LeaveSwarmCmd command) {
2224
webTarget = booleanQueryParam(webTarget, "force", command.hasForceEnabled());
2325

2426
LOGGER.trace("POST: {}", webTarget);
25-
webTarget.request().accept(MediaType.APPLICATION_JSON)
26-
.post(null);
27+
try {
28+
webTarget.request().accept(MediaType.APPLICATION_JSON).post(null).close();
29+
} catch (IOException e) {
30+
throw new RuntimeException(e);
31+
}
2732

2833
return null;
2934
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/PauseContainerCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.github.dockerjava.core.MediaType;
99
import com.github.dockerjava.core.WebTarget;
1010

11+
import java.io.IOException;
12+
1113
public class PauseContainerCmdExec extends AbstrSyncDockerCmdExec<PauseContainerCmd, Void> implements
1214
PauseContainerCmd.Exec {
1315

@@ -23,7 +25,11 @@ protected Void execute(PauseContainerCmd command) {
2325
command.getContainerId());
2426

2527
LOGGER.trace("POST: {}", webResource);
26-
webResource.request().accept(MediaType.APPLICATION_JSON).post(null);
28+
try {
29+
webResource.request().accept(MediaType.APPLICATION_JSON).post(null).close();
30+
} catch (IOException e) {
31+
throw new RuntimeException(e);
32+
}
2733

2834
return null;
2935
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/PingCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.github.dockerjava.core.DockerClientConfig;
88
import com.github.dockerjava.core.WebTarget;
99

10+
import java.io.IOException;
11+
1012
public class PingCmdExec extends AbstrSyncDockerCmdExec<PingCmd, Void> implements PingCmd.Exec {
1113

1214
private static final Logger LOGGER = LoggerFactory.getLogger(PingCmdExec.class);
@@ -20,7 +22,11 @@ protected Void execute(PingCmd command) {
2022
WebTarget webResource = getBaseResource().path("/_ping");
2123

2224
LOGGER.trace("GET: {}", webResource);
23-
webResource.request().get();
25+
try {
26+
webResource.request().get().close();
27+
} catch (IOException e) {
28+
throw new RuntimeException(e);
29+
}
2430

2531
return null;
2632
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/RenameContainerCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99

10+
import java.io.IOException;
11+
1012
public class RenameContainerCmdExec extends AbstrSyncDockerCmdExec<RenameContainerCmd, Void>
1113
implements RenameContainerCmd.Exec {
1214
private static final Logger LOG = LoggerFactory.getLogger(RenameContainerCmdExec.class);
@@ -22,7 +24,11 @@ protected Void execute(RenameContainerCmd command) {
2224
.queryParam("name", command.getName());
2325

2426
LOG.trace("POST: {}", webResource);
25-
webResource.request().accept(MediaType.APPLICATION_JSON).post(null);
27+
try {
28+
webResource.request().accept(MediaType.APPLICATION_JSON).post(null).close();
29+
} catch (IOException e) {
30+
throw new RuntimeException(e);
31+
}
2632

2733
return null;
2834
}

docker-java-core/src/main/java/com/github/dockerjava/core/exec/RestartContainerCmdExec.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.github.dockerjava.core.MediaType;
99
import com.github.dockerjava.core.WebTarget;
1010

11+
import java.io.IOException;
12+
1113
public class RestartContainerCmdExec extends AbstrSyncDockerCmdExec<RestartContainerCmd, Void> implements
1214
RestartContainerCmd.Exec {
1315

@@ -27,7 +29,11 @@ protected Void execute(RestartContainerCmd command) {
2729
}
2830

2931
LOGGER.trace("POST: {}", webResource);
30-
webResource.request().accept(MediaType.APPLICATION_JSON).post(null);
32+
try {
33+
webResource.request().accept(MediaType.APPLICATION_JSON).post(null).close();
34+
} catch (IOException e) {
35+
throw new RuntimeException(e);
36+
}
3137

3238
return null;
3339
}

0 commit comments

Comments
 (0)