fix: thread safety + resource leaks in NetUtils, Base64Command, KeymapCommand#3175
fix: thread safety + resource leaks in NetUtils, Base64Command, KeymapCommand#3175srpatcha wants to merge 1 commit into
Conversation
fe36c43 to
b23b6c3
Compare
c1bac7c to
017ef0d
Compare
|
Hi maintainers, force-pushed an updated PR ( New bug fixes pushed in this round
CLA fixSquashed all 3 prior commits into a single signed commit authored under @CLAassistant recheck |
This PR bundles three improvements to arthas core commands:
1. NetUtils / Base64Command / KeymapCommand: close resource leaks
on stream/reader/socket where the original code missed the close()
in error paths. Wrapped in try-with-resources.
2. TimeTunnelCommand: fix two race conditions:
- timeFragmentMap was a plain LinkedHashMap mutated from multiple
threads (request handlers + the AdviceListener); replaced with
Collections.synchronizedMap to make individual ops atomic.
- processSearch() iterated entrySet() without holding the
synchronizedMap monitor, which could throw
ConcurrentModificationException per the SynchronizedMap JavaDoc.
Wrapped iteration in synchronized(timeFragmentMap){...}.
3. ThreadContentionCommand: new monitor command for thread contention
analysis (deadlocks, lock waiters, wait chains). Includes:
- Null-safe iteration over ThreadMXBean.dumpAllThreads() which can
return arrays containing null elements for threads that died
between the snapshot call and the data fill.
- finally block now restores the original
threadContentionMonitoringEnabled state instead of leaving it
permanently enabled (which has measurable per-monitor overhead).
Squashed and re-authored under srpatcha@users.noreply.github.com so the
CLA assistant bot can verify a single contributor identity per the same
pattern requested by KomachiSion on alibaba/nacos #14951.
Signed-off-by: Srikanth Patchava <srpatcha@users.noreply.github.com>
017ef0d to
e09cba6
Compare
Changes
1. Wrap timeFragmentMap with
Collections.synchronizedMap()Fixes thread safety issue in time-tunnel command.
2. Fix resource leaks (
NetUtils.java,Base64Command.java,KeymapCommand.java)FileOutputStreamfor output file was never closed. Wrapped in try-with-resources.BufferedReaderfor inputrc was never properly closed. Converted to try-with-resources.