Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A NullPointerException was thrown while the node was running #5812

Closed
CSGT-KZ opened this issue May 6, 2024 · 6 comments · Fixed by #5831
Closed

A NullPointerException was thrown while the node was running #5812

CSGT-KZ opened this issue May 6, 2024 · 6 comments · Fixed by #5831
Labels

Comments

@CSGT-KZ
Copy link

CSGT-KZ commented May 6, 2024

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

@xxo1shine
Copy link
Contributor

@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
Copy link
Contributor

jwrct commented May 6, 2024

@ss334452 What is the probability of this concurrency issue occurring?

@zeusoo001
Copy link
Contributor

@jwrct The probability of occurrence is extremely low and has no impact on the system.

@jwrct
Copy link
Contributor

jwrct commented May 10, 2024

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

@zeusoo001
Copy link
Contributor

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

@zeusoo001
Copy link
Contributor

Fixed in this PR: #5831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants