Skip to content

Commit 1cddf1c

Browse files
committed
CLOUD-1461 HttpConnections not being released when using KubePing
The handler did not close the HttpExchange, which lead to HttpConnections not being removed from a Set in ServerImpl. With this commit, it is now closed properly. A proper HTTP response has also been added.
1 parent 77214fb commit 1cddf1c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

common/src/main/java/org/openshift/ping/common/server/JBossServer.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
* @author <a href="mailto:[email protected]">Ales Justin</a>
3131
*/
3232
public class JBossServer extends AbstractServer {
33+
private static final byte[] RESPONSE_BYTES = "OK".getBytes();
34+
3335
private HttpServer server;
3436

3537
public JBossServer(int port) {
@@ -77,15 +79,20 @@ private Handler(Server server) {
7779
}
7880

7981
public void handle(HttpExchange exchange) throws IOException {
80-
exchange.sendResponseHeaders(200, 0);
8182
try {
82-
String clusterName = exchange.getRequestHeaders().getFirst(CLUSTER_NAME);
83-
Channel channel = server.getChannel(clusterName);
84-
try (InputStream stream = exchange.getRequestBody()) {
85-
handlePingRequest(channel, stream);
83+
try {
84+
String clusterName = exchange.getRequestHeaders().getFirst(CLUSTER_NAME);
85+
Channel channel = server.getChannel(clusterName);
86+
try (InputStream stream = exchange.getRequestBody()) {
87+
handlePingRequest(channel, stream);
88+
}
89+
exchange.sendResponseHeaders(200, RESPONSE_BYTES.length);
90+
exchange.getResponseBody().write(RESPONSE_BYTES);
91+
} catch (Exception e) {
92+
throw new IOException(e);
8693
}
87-
} catch (Exception e) {
88-
throw new IOException(e);
94+
} finally {
95+
exchange.close();
8996
}
9097
}
9198
}

0 commit comments

Comments
 (0)