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.
This fixes a number of bugs I found while testing this both manually in VS Code and by running tests with high enough
-count
.run()
is executing, another goroutine (e.g. one executing a different operation) could have finished and triggered anothertryDispatchingModuleOp
which then filled the channel and the nexttryDispatchingModuleOp
triggered fromrun()
as a result of retry would block, therefore blocking the main loop.tryDispatchingModuleOp
in an additional goroutinetryDispatchingModuleOp
can get triggered by many threads at the same time and its original implementation left an opportunity for race condition due toqueue.Peek()
relying onqueue.Len()
but the reliance was not guaranteed in any way. AdditionallyPeek
could have "peeked" at the exact same operation more than once, which then resulted in that duplicate operation being dispatched.Peek
method entirely and ensuring we never pop from an empty queue by utilizing the internal mutex. Retries should be rare enough that (especially with the 100ms delay) shouldn't cause concern wrt resource consumption by repeated push/pop.tryDispatchingModuleOp
was triggered from inside ofexecuteModuleOp
, but loading counters were being decremented viadefer
after, which could've caused the dispatch attempt to fail when the queue was full, just because the two operations were done in the wrong order.defer
and callingtryDispatchingModuleOp
from the main loop inrun()
where we can better control the order.