From af7ad4f3662020ff1081f1669c70d6f1788209f8 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Sat, 3 Mar 2018 21:08:35 -0800 Subject: [PATCH] [TEST][Monitoring] Move payload = null above call (elastic/x-pack-elasticsearch#4053) This moves the `payload = null;` statement to above the asynchronous HTTP call. This helps to avoid a race condition relative to `doClose` asserting that it is `null`. This is only a realistic situation during a shutdown situation because the thread responds immediately before it can be nullified and freeable, which is not a realistic scenario in any other situation. Original commit: elastic/x-pack-elasticsearch@eb3a6ff11822455d361a12b6e685a7b07ecfeafe --- .../xpack/monitoring/exporter/http/HttpExportBulk.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulk.java b/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulk.java index 633b41d212d..ff9d9b786ba 100644 --- a/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulk.java +++ b/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExportBulk.java @@ -96,6 +96,9 @@ class HttpExportBulk extends ExportBulk { } else if (payload.length != 0) { final HttpEntity body = new ByteArrayEntity(payload, ContentType.APPLICATION_JSON); + // free the memory + payload = null; + client.performRequestAsync("POST", "/_bulk", params, body, new ResponseListener() { @Override public void onSuccess(Response response) { @@ -115,9 +118,6 @@ class HttpExportBulk extends ExportBulk { } } }); - - // free the memory - payload = null; } }