diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionFilter.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionFilter.java index 9a29e8c9fe0..fd75f03eae5 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionFilter.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionFilter.java @@ -87,7 +87,8 @@ public class ShieldActionFilter extends AbstractComponent implements ActionFilte throw LicenseUtils.newComplianceException(ShieldPlugin.NAME); } - try (ThreadContext.StoredContext original = threadContext.newStoredContext()) { + final ThreadContext.StoredContext original = threadContext.newStoredContext(); + try { if (licenseState.securityEnabled()) { // FIXME yet another hack. Needed to work around something like /* @@ -131,7 +132,7 @@ public class ShieldActionFilter extends AbstractComponent implements ActionFilte interceptor.intercept(request, user); } } - chain.proceed(task, action, request, new SigningListener(this, listener)); + chain.proceed(task, action, request, new SigningListener(this, listener, original)); return; } } @@ -158,11 +159,12 @@ public class ShieldActionFilter extends AbstractComponent implements ActionFilte interceptor.intercept(request, user); } } - chain.proceed(task, action, request, new SigningListener(this, listener)); + chain.proceed(task, action, request, new SigningListener(this, listener, original)); } else { chain.proceed(task, action, request, listener); } } catch (Throwable t) { + original.restore(); listener.onFailure(t); } } @@ -228,14 +230,17 @@ public class ShieldActionFilter extends AbstractComponent implements ActionFilte private final ShieldActionFilter filter; private final ActionListener innerListener; + private final ThreadContext.StoredContext threadContext; - private SigningListener(ShieldActionFilter filter, ActionListener innerListener) { + private SigningListener(ShieldActionFilter filter, ActionListener innerListener, ThreadContext.StoredContext threadContext) { this.filter = filter; this.innerListener = innerListener; + this.threadContext = threadContext; } @Override @SuppressWarnings("unchecked") public void onResponse(Response response) { + threadContext.restore(); try { response = this.filter.sign(response); innerListener.onResponse(response); @@ -246,6 +251,7 @@ public class ShieldActionFilter extends AbstractComponent implements ActionFilte @Override public void onFailure(Throwable e) { + threadContext.restore(); innerListener.onFailure(e); } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index 3e2a47c05c3..cea6b3fa9aa 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.watcher.test; -import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; import org.elasticsearch.action.search.SearchRequestBuilder; @@ -102,7 +101,6 @@ import static org.hamcrest.core.IsNot.not; /** */ @ClusterScope(scope = SUITE, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, maxNumDataNodes = 3) -@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/x-plugins/issues/1380") public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase { private static final boolean timeWarpEnabled = SystemPropertyUtil.getBoolean("tests.timewarp", true);