A NullPointerException was thrown while the node was running
CSGT-KZ opened this issue · 6 comments
@CSGT-KZ There is a concurrent access problem with the fetchBlockInfo object. The concurrency steps are as follows.
- The
request block thread
assigns a value to the fetchBlockInfo object - The
fetchBlock thread
sets the fetchBlockInfo object to null - A null pointer exception occurs when the
request block thread
accesses the fetchBlockInfo object.
@ss334452 What is the probability of this concurrency issue occurring?
@jwrct The probability of occurrence is extremely low and has no impact on the system.
@zeusoo001 Even though the probability of this concurrency issue occurring is low and does not affect the system, after all, the program threw an exception, which is not the expected result, right? Do you think it's necessary to fix this problem? Or maybe you already have a solution to fix it?
@jwrct Considering the strictness of the code, it needs to be repaired. The repair plan is not to directly access the fetchBlockInfo
object when printing the log. The modification is as follows.
fetchBlockInfo = new FetchBlockInfo(sha256Hash, peer, System.currentTimeMillis());
logger.info("Set fetchBlockInfo, block: {}, peer: {}, time: {}", sha256Hash,
fetchBlockInfo.getPeer().getInetAddress(), fetchBlockInfo.getTime());
change into
long now = System.currentTimeMillis();
fetchBlockInfo = new FetchBlockInfo(sha256Hash, peer, now);
logger.info("Set fetchBlockInfo, block: {}, peer: {}, time: {}", sha256Hash,
peer.getInetAddress(), now);