Synchronize lazy initialization in ProcessConsoleManager.getColorProvider#2805
Open
vogella wants to merge 1 commit into
Open
Synchronize lazy initialization in ProcessConsoleManager.getColorProvider#2805vogella wants to merge 1 commit into
vogella wants to merge 1 commit into
Conversation
iloveeclipse
reviewed
Jul 7, 2026
Contributor
ConsoleCreation jobs run in parallel and share the singleton ProcessConsoleManager. getColorProvider(String) lazily initialized the fColorProviders map and the default color provider without any synchronization, so concurrent jobs could corrupt the HashMap during parallel put() calls and could create and return two different default color providers. Initialize both lazily in a lock-free way so no lock is held across calls into the extension registry (which could deadlock with 3rd party code): - fColorProviders is volatile and built into a local map before being published. A concurrent duplicate build is harmless because each thread fills its own local map and only the published reference is used. - The default color provider is stored in an AtomicReference and created via compareAndSet, guaranteeing a single shared instance. Fixes eclipse-platform#2637 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3730df3 to
1fece62
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ConsoleCreationjobs run in parallel but share the singletonProcessConsoleManager.getColorProvider(String)lazily initializedfColorProviders(a plainHashMap) and the defaultConsoleColorProviderwithout synchronization, so concurrent first calls could corrupt the map via parallelput()or create two different default providers (#2637).Fix
Initialize both lazily in a lock-free way, so no lock is held across the extension-registry calls (which could deadlock with 3rd-party code):
fColorProvidersisvolatileand built into a local map before being published; a concurrent duplicate build is harmless because each thread fills its own local map.AtomicReferenceand created viacompareAndSet, guaranteeing a single shared instance.Intentionally isolated to the init race (#2637); the shared stateful default provider (#2638 / #596) is left for a follow-up.
Fixes #2637