From 23c15510d1b1c22e151cf516ad8bcc4bc4279b89 Mon Sep 17 00:00:00 2001 From: jobayle Date: Mon, 14 Oct 2019 11:37:19 +0200 Subject: [PATCH] Properly close responses returned by POST requests --- .../metrics/influxdb/io/InfluxDbHttpWriter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/kickstarter/dropwizard/metrics/influxdb/io/InfluxDbHttpWriter.java b/src/main/java/com/kickstarter/dropwizard/metrics/influxdb/io/InfluxDbHttpWriter.java index fbd4e6b..013c06a 100644 --- a/src/main/java/com/kickstarter/dropwizard/metrics/influxdb/io/InfluxDbHttpWriter.java +++ b/src/main/java/com/kickstarter/dropwizard/metrics/influxdb/io/InfluxDbHttpWriter.java @@ -8,6 +8,7 @@ import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.Range; @@ -32,7 +33,16 @@ public InfluxDbHttpWriter(final Client client, final String endpoint) { @Override public void writeBytes(final byte[] bytes) { - influxLines.request().post(Entity.entity(bytes, MediaType.APPLICATION_OCTET_STREAM_TYPE)); + Response response = null; + try { + response = influxLines.request() + .post(Entity.entity(bytes, MediaType.APPLICATION_OCTET_STREAM_TYPE)); + } + finally { + if (response != null) { + response.close(); + } + } } @Override