fix: use idle() instead of length() to guard queue drain#1236
Merged
Conversation
queue.length() only counts items waiting in the queue, not items currently being processed by workers. When all items are dequeued but still running, length() returns 0 and drain() is skipped, causing non-deterministic incomplete results. queue.idle() correctly checks both waiting AND running items.
|
Published under $ sf plugins install sf-git-merge-driver@dev-1236 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1236 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 58 58
Lines 1544 1544
Branches 194 194
=========================================
Hits 1544 1544 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Shipped in release $ sf plugins install sfdx-git-delta@latest-rc
# Or
$ sf plugins install sfdx-git-delta@v6.33.0💡 Enjoying sfdx-git-delta? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Explain your changes
Race condition fix in
DiffLineInterpreter.process(). Theasync.queue.length()method only counts items waiting in the queue, not items currently being processed by workers. When all items were dequeued but workers were still running,length()returned 0 anddrain()was skipped — causing the method to return incomplete results non-deterministically.Replaced
processor.length() > 0with!processor.idle(), which correctly checks both waiting AND running items.Note:
drain()cannot be called unconditionally because it hangs forever on an already-idle queue inasync@3.x. The guard is necessary but must useidle()instead oflength().Does this close any currently open issues?
closes #1235
Any particular element that can be tested locally
Run
npx jest __tests__/unit/lib/service/diffLineInterpreter.test.ts— the new test "Given slow handlers, When queue workers finish after enqueuing, Then all results are collected" verifies that delayed handler results are fully collected.Any other comments
Root cause analysis:
length()running()idle()Controlled test showed 100% failure with the old guard vs 0% failure with
!idle().