Skip to content

[6.4] Fix AsyncQueue cleanup leak and dependency metadata bug#53

Merged
rintaro merged 2 commits into
swiftlang:release/6.4.xfrom
rintaro:6.4-asyncqueue-fixes-and-mutex
May 22, 2026
Merged

[6.4] Fix AsyncQueue cleanup leak and dependency metadata bug#53
rintaro merged 2 commits into
swiftlang:release/6.4.xfrom
rintaro:6.4-asyncqueue-fixes-and-mutex

Conversation

@rintaro
Copy link
Copy Markdown
Member

@rintaro rintaro commented May 21, 2026

Cherry-pick #52 (minus Mutex migration) into release/6.4.x

  • Explanation: Fixes two correctness bugs in AsyncQueue:
    1. PendingTask entries leaked from tasksByMetadata when the operation threw or the task was cancelled. Cleanup was placed after operation() instead of in a defer, so the dictionary grew unboundedly per failed task.
    2. The "wait only on the bucket's last task" dependency optimization checked metadata.isDependency(of: metadata) (the new task's self-dependency) instead of pendingMetadata.isDependency(of: pendingMetadata) (the bucket's). When the new task was self-serializing but its dependency bucket was not, the new task could start before earlier concurrent tasks in that bucket finished.
  • Scope: AsyncQueue (request handling queues and background index scheduling in sourcekit-lsp)
  • Risk: Low.
    1. mechanical move of cleanup into a defer; no behavior change for the success path.
    2. one-line correction of a metadata reference inside an existing optimization branch. The fix is strictly more conservative, so it can only block tasks that were previously released too early.
  • Testing: Added regression test case
  • Issues: N/A
  • Reviewer: Alex Hoppen (@ahoppen)

- Wrap PendingTask removal in `defer` so a thrown or cancelled
  operation no longer leaves stale entries in `tasksByMetadata`.
- The "depend only on the bucket's last task" optimization checked
  `metadata.isDependency(of: metadata)` (the new task's self-dep)
  instead of `pendingMetadata.isDependency(of: pendingMetadata)`
  (the bucket's). With cross-metadata dependencies, the new task
  could start before earlier concurrent tasks in that bucket.

(cherry picked from commit ae2e9df)
@rintaro rintaro changed the base branch from main to release/6.4.x May 22, 2026 02:14
@rintaro rintaro force-pushed the 6.4-asyncqueue-fixes-and-mutex branch from 978cc09 to c09ebad Compare May 22, 2026 06:34
Verifies the bucket-self-dependency optimization waits on every
entry in the bucket, not just the last.

(cherry picked from commit 151e6fc)
@rintaro rintaro force-pushed the 6.4-asyncqueue-fixes-and-mutex branch from c09ebad to 4b06670 Compare May 22, 2026 15:20
@rintaro rintaro merged commit 1ec290a into swiftlang:release/6.4.x May 22, 2026
99 of 106 checks passed
@rintaro rintaro deleted the 6.4-asyncqueue-fixes-and-mutex branch May 22, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants