eolivelli opened a new pull request, #22767:
URL: https://github.com/apache/pulsar/pull/22767

   ### Motivation
   
   When unloading a topic the `EntryFilterWithClassLoader` instance closes the 
NarClassLoader that loaded the filter, preventing any further loading of 
classes.
   
   
   This is a regression introduced in 3.0.0 by 
https://github.com/apache/pulsar/pull/19364
   
   
   Reproducer:
   - configure one EntryFilter in broker.conf
   - create a topic (this in turn creates an `EntryFilterWithClassLoader` 
instance)
   - do not use the EntryFilter (don't consume messages)
   - unload the topic (this calls EntryFilterWithClassLoader.close() that calls 
ClassLoader.close())
   - consume data from any topic that uses the entry filter
   - CRASH ! because the Classloader is closed and it cannot load any other 
classes
   
   Sample Stacktrace (this is from the DataStax fork, but it shows the problem):
   ```
   2024-05-09T13:16:13,145+0000 [broker-topic-workers-OrderedExecutor-0-0] 
ERROR org.apache.bookkeeper.common.util.SingleThreadExecutor - Error while 
running task: com/datastax/oss/pulsar/jms/selectors/SelectorSupport
   java.lang.NoClassDefFoundError: 
com/datastax/oss/pulsar/jms/selectors/SelectorSupport
           at 
com.datastax.oss.pulsar.jms.selectors.JMSFilter.parseSelector(JMSFilter.java:309)
 ~[?:?]
           at 
com.datastax.oss.pulsar.jms.selectors.JMSFilter.filterEntry(JMSFilter.java:245) 
~[?:?]
           at 
com.datastax.oss.pulsar.jms.selectors.JMSFilter.filterEntry(JMSFilter.java:130) 
~[?:?]
           at 
org.apache.pulsar.broker.service.plugin.EntryFilterWithClassLoader.filterEntry(EntryFilterWithClassLoader.java:41)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.pulsar.broker.service.EntryFilterSupport.getFilterResult(EntryFilterSupport.java:85)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.pulsar.broker.service.EntryFilterSupport.runFiltersForEntry(EntryFilterSupport.java:66)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.pulsar.broker.service.AbstractBaseDispatcher.filterEntriesForConsumer(AbstractBaseDispatcher.java:151)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers.trySendMessagesToConsumers(PersistentDispatcherMultipleConsumers.java:749)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers.sendMessagesToConsumers(PersistentDispatcherMultipleConsumers.java:654)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.pulsar.broker.service.persistent.PersistentDispatcherMultipleConsumers.lambda$readEntriesComplete$8(PersistentDispatcherMultipleConsumers.java:619)
 ~[com.datastax.oss-pulsar-broker-3.1.4.1-SNAPSHOT.jar:3.1.4.1-SNAPSHOT]
           at 
org.apache.bookkeeper.common.util.SingleThreadExecutor.safeRunTask(SingleThreadExecutor.java:137)
 ~[org.apache.bookkeeper-bookkeeper-common-4.16.5xxxx]
           at 
org.apache.bookkeeper.common.util.SingleThreadExecutor.run(SingleThreadExecutor.java:113)
 ~[org.apache.bookkeeper-bookkeeper-common-4.16.5xxxx]
           at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
 ~[io.netty-netty-common-4.1.108.Final.jar:4.1.108.Final]
           at java.lang.Thread.run(Thread.java:842) ~[?:?]
   Caused by: java.lang.ClassNotFoundException: 
com.datastax.oss.pulsar.jms.selectors.SelectorSupport
           at java.net.URLClassLoader.findClass(URLClassLoader.java:445) ~[?:?]
           at java.lang.ClassLoader.loadClass(ClassLoader.java:587) ~[?:?]
           at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
           ... 14 more
   ```
   
   ### Modifications
   
   Mofications:
   - make it clear that EntryFilterWithClassLoader is not owning the classloader
   - enforce also using the Thread ContextClassloader in 
EntryFilterWithClassLoader (this is another problem, but it didn't affect the 
specific usecase reported by the user)
   
   ### Verifying this change
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   ### Does this pull request potentially affect one of the following parts:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update 
later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: <!-- ENTER URL HERE -->
   
   <!--
   After opening this PR, the build in apache/pulsar will fail and instructions 
will
   be provided for opening a PR in the PR author's forked repository.
   
   apache/pulsar pull requests should be first tested in your own fork since 
the 
   apache/pulsar CI based on GitHub Actions has constrained resources and quota.
   GitHub Actions provides separate quota for pull requests that are executed 
in 
   a forked repository.
   
   The tests will be run in the forked repository until all PR review comments 
have
   been handled, the tests pass and the PR is approved by a reviewer.
   -->
   


-- 
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