From a27042901ad539dfc0c0b172fc9c3994d4863a87 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Tue, 2 Jan 2024 17:58:30 -0600 Subject: [PATCH] fixing RestIndexAction --- .../rest/action/document/RestIndexAction.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 443f5734f969c..2a5d9749723c9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -8,6 +8,7 @@ package org.elasticsearch.rest.action.document; +import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.index.IndexRequest; @@ -145,10 +146,14 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC return channel -> client.index( indexRequest, - new RestToXContentListener<>(channel, DocWriteResponse::status, r -> r.getLocation(indexRequest.routing())) + ActionListener.runAfter( + new RestToXContentListener<>(channel, DocWriteResponse::status, r -> r.getLocation(indexRequest.routing())), + indexRequest::decRef + ) ); - } finally { + } catch (Exception e) { indexRequest.decRef(); + throw e; } }