tronprotocol/java-tron

A NullPointerException was thrown while the node was running

CSGT-KZ opened this issue · 6 comments

System information

Java-tron version: v4.7.4
OS & Version: Linux & macOS

Expected behavior

NullPointerException should not be thrown.

Actual behavior

When checking the node's log, I found a NullPointerException:
image

Frequency

1 time

@CSGT-KZ There is a concurrent access problem with the fetchBlockInfo object. The concurrency steps are as follows.

  1. The request block thread assigns a value to the fetchBlockInfo object
  2. The fetchBlock thread sets the fetchBlockInfo object to null
  3. A null pointer exception occurs when the request block thread accesses the fetchBlockInfo object.
jwrct commented

@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.

jwrct commented

@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);

Fixed in this PR: #5831