Search: Sending a request that fails to parse can cause file leaks, closes #270.

This commit is contained in:
kimchy 2010-07-21 16:59:58 +03:00
parent 0cb97e4044
commit 8ec7ee66a9
2 changed files with 35 additions and 31 deletions

View File

@ -286,12 +286,13 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
private SearchContext createContext(InternalSearchRequest request) throws ElasticSearchException {
IndexService indexService = indicesService.indexServiceSafe(request.index());
IndexShard indexShard = indexService.shardSafe(request.shardId());
Engine.Searcher engineSearcher = indexShard.searcher();
SearchShardTarget shardTarget = new SearchShardTarget(clusterService.state().nodes().localNodeId(), request.index(), request.shardId());
Engine.Searcher engineSearcher = indexShard.searcher();
SearchContext context = new SearchContext(idGenerator.incrementAndGet(), shardTarget, request.numberOfShards(), request.timeout(), request.types(), engineSearcher, indexService, scriptService);
try {
context.scroll(request.scroll());
parseSource(context, request.source(), request.sourceOffset(), request.sourceLength());
@ -318,6 +319,10 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> {
context.keepAlive(keepAlive);
context.accessed(timerService.estimatedTimeInMillis());
context.keepAliveTimeout(timerService.newTimeout(new KeepAliveTimerTask(context), keepAlive, TimerService.ExecutionType.DEFAULT));
} catch (RuntimeException e) {
context.release();
throw e;
}
return context;
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.search.internal;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.store.AlreadyClosedException;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.timer.Timeout;
@ -45,7 +44,6 @@ import org.elasticsearch.search.fetch.script.ScriptFieldsContext;
import org.elasticsearch.search.highlight.SearchContextHighlight;
import org.elasticsearch.search.query.QuerySearchResult;
import java.io.IOException;
import java.util.List;
/**
@ -136,15 +134,16 @@ public class SearchContext implements Releasable {
}
@Override public boolean release() throws ElasticSearchException {
// we should close this searcher, since its a new one we create each time, and we use the IndexReader
try {
searcher.close();
} catch (IOException e) {
// ignore this exception
} catch (AlreadyClosedException e) {
// ignore this as well
} catch (Exception e) {
// ignore any exception here
}
engineSearcher.release();
if (keepAliveTimeout != null) {
keepAliveTimeout.cancel();
}
return true;
}