Skip to content

Commit 91b88e7

Browse files
authored
Merge pull request #106 from brendandburns/close
Fix up some potential leaks, by calling close()
2 parents ca70501 + 6529645 commit 91b88e7

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

examples/src/main/java/io/kubernetes/client/examples/AttachExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void main(String[] args) throws IOException, ApiException, Interru
4242
Configuration.setDefaultApiClient(client);
4343

4444
Attach attach = new Attach();
45-
final Attach.AttachResult result = attach.attach("default", "nginx-2371676037-czqx3", true);
45+
final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);
4646

4747
new Thread(new Runnable() {
4848
public void run() {
@@ -72,7 +72,7 @@ public void run() {
7272
}).start();
7373

7474
Thread.sleep(10*1000);
75-
75+
result.close();
7676
System.exit(0);
7777
}
7878
}

examples/src/main/java/io/kubernetes/client/examples/ExecExample.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void main(String[] args) throws IOException, ApiException, Interru
4444
Exec exec = new Exec();
4545
boolean tty = System.console() != null;
4646
// final Process proc = exec.exec("default", "nginx-2371676037-czqx3", new String[] {"sh", "-c", "echo foo"}, true, tty);
47-
final Process proc = exec.exec("default", "nginx-2371676037-czqx3", new String[] {"sh"}, true, tty);
47+
final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[] {"sh"}, true, tty);
4848

4949

5050
new Thread(new Runnable() {
@@ -75,6 +75,8 @@ public void run() {
7575
ex.printStackTrace();
7676
}
7777

78+
proc.destroy();
79+
7880
System.exit(0);
7981
}
8082
}

util/src/main/java/io/kubernetes/client/Attach.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public AttachResult attach(String namespace, String name, String container, bool
145145
* AttachResult contains the result of an Attach call, it includes streams for stdout
146146
* stderr and stdin.
147147
*/
148-
public static class AttachResult {
148+
public static class AttachResult implements java.io.Closeable {
149149
private WebSocketStreamHandler handler;
150150

151151

@@ -164,5 +164,9 @@ public InputStream getStandardOutputStream() throws IOException {
164164
public InputStream getErrorStream() throws IOException {
165165
return handler.getInputStream(2);
166166
}
167+
168+
public void close() {
169+
handler.close();
170+
}
167171
}
168172
}

util/src/main/java/io/kubernetes/client/ProtoClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public <T extends Message> ObjectOrStatus<T> request(T.Builder builder, String p
167167
}
168168
Response resp = apiClient.getHttpClient().newCall(request).execute();
169169
Unknown u = parse(resp.body().byteStream());
170+
resp.body().close();
171+
170172
if (u.getTypeMeta().getApiVersion().equals("v1") &&
171173
u.getTypeMeta().getKind().equals("Status")) {
172174
Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();

util/src/main/java/io/kubernetes/client/util/WebSocketStreamHandler.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* WebSocketStreamHandler understands the Kubernetes streaming protocol and separates
3737
* a single WebSockets stream into a number of different streams using that protocol.
3838
*/
39-
public class WebSocketStreamHandler implements WebSockets.SocketListener {
39+
public class WebSocketStreamHandler implements WebSockets.SocketListener, Closeable {
4040
Map<Integer, PipedOutputStream> output;
4141
Map<Integer, PipedInputStream> input;
4242
WebSocket socket;
@@ -95,14 +95,6 @@ public void close() {
9595
ex.printStackTrace();
9696
}
9797
}
98-
/*
99-
try {
100-
socket.close(1000, "User closed connection");
101-
} catch (IOException ex) {
102-
// TODO use a logger here
103-
ex.printStackTrace();
104-
}
105-
*/
10698
}
10799

108100
/**

0 commit comments

Comments
 (0)