This is an automated email from the ASF dual-hosted git repository. technoboy pushed a commit to branch branch-3.2 in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-3.2 by this push: new 2c92ae31722 [fix][fn]make sure the classloader for ContextImpl is `functionClassLoader` in different runtimes (#22501) 2c92ae31722 is described below commit 2c92ae317222ac3e434a497aa458792f88debe75 Author: Rui Fu <freez...@users.noreply.github.com> AuthorDate: Wed May 1 13:18:05 2024 +0800 [fix][fn]make sure the classloader for ContextImpl is `functionClassLoader` in different runtimes (#22501) --- .../apache/pulsar/functions/instance/JavaInstanceRunnable.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java index 21f125d3497..f1b9af00f9d 100644 --- a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java +++ b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java @@ -283,13 +283,19 @@ public class JavaInstanceRunnable implements AutoCloseable, Runnable { Logger instanceLog = LoggerFactory.getILoggerFactory().getLogger( "function-" + instanceConfig.getFunctionDetails().getName()); Thread currentThread = Thread.currentThread(); + ClassLoader clsLoader = currentThread.getContextClassLoader(); Consumer<Throwable> fatalHandler = throwable -> { this.deathException = throwable; currentThread.interrupt(); }; - return new ContextImpl(instanceConfig, instanceLog, client, secretsProvider, + try { + Thread.currentThread().setContextClassLoader(functionClassLoader); + return new ContextImpl(instanceConfig, instanceLog, client, secretsProvider, collectorRegistry, metricsLabels, this.componentType, this.stats, stateManager, pulsarAdmin, clientBuilder, fatalHandler); + } finally { + Thread.currentThread().setContextClassLoader(clsLoader); + } } public interface AsyncResultConsumer {