This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit d23c77bc61a307d3e2b900584d8e98e4037d92b5
Author: Rui Fu <[email protected]>
AuthorDate: Wed May 1 13:18:05 2024 +0800

    [fix][fn]make sure the classloader for ContextImpl is `functionClassLoader` 
in different runtimes (#22501)
    
    (cherry picked from commit d067efcc67f761babd056e1db2b9c7c1dc419a1b)
---
 .../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 e2ad9e4c989..28f3dbe3cfb 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
@@ -272,9 +272,15 @@ public class JavaInstanceRunnable implements 
AutoCloseable, Runnable {
     ContextImpl setupContext() throws PulsarClientException {
         Logger instanceLog = LoggerFactory.getILoggerFactory().getLogger(
                 "function-" + instanceConfig.getFunctionDetails().getName());
-        return new ContextImpl(instanceConfig, instanceLog, client, 
secretsProvider,
+        ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(functionClassLoader);
+            return new ContextImpl(instanceConfig, instanceLog, client, 
secretsProvider,
                 collectorRegistry, metricsLabels, this.componentType, 
this.stats, stateManager,
                 pulsarAdmin, clientBuilder);
+        } finally {
+            Thread.currentThread().setContextClassLoader(clsLoader);
+        }
     }
 
     public interface AsyncResultConsumer {

Reply via email to