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

Fix the potential risk to get null CurrentHeaderHash from Blockchain (2x) #1030

Conversation

yongjiema
Copy link
Contributor

No description provided.

@erikzhang
Copy link
Member

What's the difference?

@yongjiema yongjiema changed the title Fix the potential risk to get null CurrentHeaderHash from Blockchain Fix the potential risk to get null CurrentHeaderHash from Blockchain (2x) Aug 15, 2019
@yongjiema
Copy link
Contributor Author

yongjiema commented Aug 15, 2019

What's the difference?

Before: Reading without lock may get null value from a changeable collection in case of multiple reading, please check https://stackoverflow.com/questions/17769892/c-sharp-multi-threaded-queue-items-are-null for more details.

After: The Interlocked.Exchange is an atomic operation which is friendly for multithreading (https://github.com/neo-project/neo/blob/master-2.x/neo/Ledger/Blockchain.cs#L729).

PS: I've encountered the issue on my local node.

@vncoelho vncoelho added the port-to-3.x Feature or PR must be ported to Neo 3.x branch label Aug 15, 2019
Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and working normally. I did not reproduce the fix, but makes sense.

Nice job you are doing @yongjiema, let's port this to 3x, right?

@yongjiema
Copy link
Contributor Author

@vncoelho This fix is for 2x, I've just created a PR #1033 for 3x.

@vncoelho vncoelho reopened this Aug 16, 2019
@vncoelho vncoelho merged commit 56174b8 into neo-project:master-2.x Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
port-to-3.x Feature or PR must be ported to Neo 3.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants