lhotari commented on code in PR #22501:
URL: https://github.com/apache/pulsar/pull/22501#discussion_r1566204680


##########
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java:
##########
@@ -283,13 +283,17 @@ ContextImpl setupContext() throws PulsarClientException {
         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,
-                collectorRegistry, metricsLabels, this.componentType, 
this.stats, stateManager,
-                pulsarAdmin, clientBuilder, fatalHandler);
+        Thread.currentThread().setContextClassLoader(functionClassLoader);
+        ContextImpl contextImpl = new ContextImpl(instanceConfig, instanceLog, 
client, secretsProvider,
+            collectorRegistry, metricsLabels, this.componentType, this.stats, 
stateManager,
+            pulsarAdmin, clientBuilder, fatalHandler);
+        Thread.currentThread().setContextClassLoader(clsLoader);
+        return contextImpl;

Review Comment:
   use a try-finally block so that the original context classloader is restored 
in the finally block. this type of solution is used in other locations where 
the context classloader is modified.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to