Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
take pruning logic out of create_transaction logic #11845
take pruning logic out of create_transaction logic #11845
Changes from 13 commits
0b2b537
257153e
f040a23
1b9c37e
d4e5a03
939d610
fc2bbc5
13d35dd
8052d49
14ae5ea
a9b2f49
55d9ace
676b07c
b026003
2d02c39
226ec84
21af152
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurred to me during our call that both PruneQueue and createTransaction touch the queue, but there's no locking on this function. As a result, its possible there could be a race condition that occurs when multiple pruneQueueAndCreateTxn calls are done at the same time. For example, if thread A calls pruneQueue and then gets pre-empted, then thread B could run pruneQueueAndCreate putting the queueSize to the max queue size, and then when thread A finishes, it could then call createTransaction when the queueSize is at maximum, thereby allowing the queue to grow beyond the max queue size.
My question here is: do we need a lock to guard the interactions with the queue within this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's a good point!
We do have a constraint in our other loops where only 1 thread is operating for each fromAddress. Thus no thread safety issues.
However the CreateTransaction method is called by the client, and can be called concurrently.
So the situation you described can potentially happen.
Note that the only harm in this case would be that our queue will momentarily grow to a larger size. As soon as there's yet another call from client, that prune will again cut down the queue size to right values.
So this isn't a big problem, except that theoretically we could have a larger queue.
I won't mind adding a new lock to prevent this situation, but even if we don't, it won't break/affect anything, according to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch patrick. Added the Lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.