Skip to content

Commit 82a4bd4

Browse files
committed
fix connector executor: restore context
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
1 parent f4ac35c commit 82a4bd4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/AwsConnectorExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.logging.log4j.Logger;
2727
import org.opensearch.common.collect.Tuple;
2828
import org.opensearch.common.util.TokenBucket;
29+
import org.opensearch.common.util.concurrent.ThreadContext;
2930
import org.opensearch.core.action.ActionListener;
3031
import org.opensearch.ml.common.connector.AwsConnector;
3132
import org.opensearch.ml.common.connector.Connector;
@@ -123,14 +124,15 @@ public void invokeRemoteService(
123124
default:
124125
throw new IllegalArgumentException("unsupported http method");
125126
}
127+
ThreadContext.StoredContext storedContext = client.threadPool().getThreadContext().newStoredContext(true);
126128
AsyncExecuteRequest executeRequest = AsyncExecuteRequest
127129
.builder()
128130
.request(signRequest(request))
129131
.requestContentPublisher(new SimpleHttpContentPublisher(request))
130132
.responseHandler(
131133
new MLSdkAsyncHttpResponseHandler(
132134
executionContext,
133-
actionListener,
135+
ActionListener.runBefore(actionListener, storedContext::restore),
134136
parameters,
135137
connector,
136138
scriptService,

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/HttpJsonConnectorExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.logging.log4j.Logger;
2626
import org.opensearch.common.collect.Tuple;
2727
import org.opensearch.common.util.TokenBucket;
28+
import org.opensearch.common.util.concurrent.ThreadContext;
2829
import org.opensearch.core.action.ActionListener;
2930
import org.opensearch.ml.common.connector.Connector;
3031
import org.opensearch.ml.common.connector.HttpConnector;
@@ -122,14 +123,15 @@ public void invokeRemoteService(
122123
default:
123124
throw new IllegalArgumentException("unsupported http method");
124125
}
126+
ThreadContext.StoredContext storedContext = client.threadPool().getThreadContext().newStoredContext(true);
125127
AsyncExecuteRequest executeRequest = AsyncExecuteRequest
126128
.builder()
127129
.request(request)
128130
.requestContentPublisher(new SimpleHttpContentPublisher(request))
129131
.responseHandler(
130132
new MLSdkAsyncHttpResponseHandler(
131133
executionContext,
132-
actionListener,
134+
ActionListener.runBefore(actionListener, storedContext::restore),
133135
parameters,
134136
connector,
135137
scriptService,

0 commit comments

Comments
 (0)