Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.4.0
Description
While tracing the block deletion logic, I found a possible problem regarding command status update logic.
The cmdStatusMap in StateContext is a ConcurrentHashMap
Currently the update logic for command status is as follows:
public boolean updateCommandStatus(Long cmdId, Consumer<CommandStatus> cmdStatusUpdater) { if (cmdStatusMap.containsKey(cmdId)) { cmdStatusUpdater.accept(cmdStatusMap.get(cmdId)); return true; } return false; }
It does not seem correct. Although the get containsKey and get is protected by the ConcurrentHashMap, the CommandStatus retrieved is mutated directly using the cmdStatusUpdater and not protected by the ConcurrentHashMap. This might trigger race condition.
We should use atomic operation like computeIfPresent.
Note: The cmdStatusMap is also exposed to public (getCommandStatusMap) which might not be a good idea since we cannot guarantee correct usage of the map. We might need to encapsulate it properly inside StateContext.
Attachments
Issue Links
- links to