Skip to content

[INLONG-12137][Audit] Resolve thread-safety issues in the Audit SDK under high concurrency#12138

Merged
dockerzhang merged 2 commits into
apache:masterfrom
doleyzi:INLONG-12137
Jun 3, 2026
Merged

[INLONG-12137][Audit] Resolve thread-safety issues in the Audit SDK under high concurrency#12138
dockerzhang merged 2 commits into
apache:masterfrom
doleyzi:INLONG-12137

Conversation

@doleyzi
Copy link
Copy Markdown
Contributor

@doleyzi doleyzi commented Jun 3, 2026

Motivation

The Audit SDK is called concurrently by multi-threaded components but is not thread-safe: non-thread-safe containers and non-atomic counter updates in the aggregation path cause lost/duplicated metrics and intermittent ConcurrentModificationException / NullPointerException. All public APIs (add / send / flush) should be thread-safe by contract.

Modifications

Replaced unsafe containers and counters in the aggregation path with ConcurrentHashMap and LongAdder / AtomicLong, reworked flush/send into a snapshot-and-swap path so producers and the flush thread never block or lose entries, and ensured all public APIs (add / send / flush) only operate on thread-safe state. Added N×M concurrent unit tests asserting exact totals with no exceptions.

@dockerzhang dockerzhang merged commit f89c9a1 into apache:master Jun 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Audit] Resolve thread-safety issues in the Audit SDK under high concurrency

4 participants