Skip to content

[Bug] Static ScheduledExecutorService in PulsarSink causes ClassLoader leaks and shared state corruption #12064

@QiuYucheng2003

Description

@QiuYucheng2003

What happened

Context:
The org.apache.inlong.audit.sink.PulsarSink class maintains a private static ScheduledExecutorService that is initialized in a static {} block.

Problem:

  1. ClassLoader Leak (NT Defect): The static thread pool (pulsarPerformance-Printer-thread) is started immediately upon class loading and holds a strong reference to the ClassLoader. In containerized or plugin environments (like Flume/Agent), this prevents the ClassLoader from being garbage collected during hot-redeployments, leading to Metaspace OOM.

  2. Shared State Corruption: Since the executor is static (global), calling stop() on any single PulsarSink instance shuts down this shared executor. This unintentionally kills the performance metric task for all other running PulsarSink instances.

What you expected to happen

  1. Instance Isolation: The ScheduledExecutorService should be an instance variable, not static.

  2. Lifecycle Management: The thread pool should be initialized in the start() method and shut down in the stop() method, ensuring it follows the lifecycle of the specific PulsarSink instance without affecting others.

How to reproduce

  1. Check the source code in org.apache.inlong.audit.sink.PulsarSink.java.

Line 129: private static ScheduledExecutorService scheduledExecutorService ...

Line 135 (Static Block): scheduledExecutorService.scheduleWithFixedDelay(...)

  1. Deploy InLong Audit with multiple PulsarSink configurations.

  2. Stop one sink instance.

  3. Result: The pulsarPerformance-Printer-thread is terminated globally, causing other sinks to stop reporting metrics.

Environment

MacOS 13.0
JDK 1.8

InLong version

master

InLong Component

InLong Audit

Are you willing to submit PR?

  • Yes, I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething is wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions