From 4558816bcf11a27839902a02d49fb35058172735 Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 30 Apr 2011 00:09:36 +0300 Subject: [PATCH] make sure we close the parser even if it failed to parse a search request --- .../main/java/org/elasticsearch/search/SearchService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java index 91d3adc7c33..4e5448d4f3f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/SearchService.java @@ -446,8 +446,9 @@ public class SearchService extends AbstractLifecycleComponent { if (source == null || length == 0) { return; } + XContentParser parser = null; try { - XContentParser parser = XContentFactory.xContent(source, offset, length).createParser(source, offset, length); + parser = XContentFactory.xContent(source, offset, length).createParser(source, offset, length); XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { @@ -471,6 +472,10 @@ public class SearchService extends AbstractLifecycleComponent { // ignore } throw new SearchParseException(context, "Failed to parse source [" + sSource + "]", e); + } finally { + if (parser != null) { + parser.close(); + } } }