Skip to content

Commit

Permalink
Fix non-synchronized access to handlers map
Browse files Browse the repository at this point in the history
The user modifies the `handlers` map from his thread. However, when a
signal is raised, it's on another thread: on Windows it's
`WindowsStreamPump`. Therefore this map is accessed from 2 threads
without synchronization.

The error manifests as handler not being called. For unknown reason, we
only observed it on Windows, but it seems the issue also affects Linux
terminals.
  • Loading branch information
viliam-durina authored and mattirn committed Jan 16, 2021
1 parent cc094c7 commit ac4cdc1
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier;

Expand All @@ -39,7 +40,7 @@ public abstract class AbstractTerminal implements Terminal {
protected final String name;
protected final String type;
protected final Charset encoding;
protected final Map<Signal, SignalHandler> handlers = new HashMap<>();
protected final Map<Signal, SignalHandler> handlers = new ConcurrentHashMap<>();
protected final Set<Capability> bools = new HashSet<>();
protected final Map<Capability, Integer> ints = new HashMap<>();
protected final Map<Capability, String> strings = new HashMap<>();
Expand Down

0 comments on commit ac4cdc1

Please sign in to comment.