Skip to content

bug(queue): AsyncQueue leaks pending resolvers on abandoned iteration #34984

Closed as not planned

Description

@HEETMEHTA18

Bug

When a consumer stops iterating a for await...of loop over AsyncQueue before consuming all items, the pending resolver callbacks in the resolvers array are never cleaned up, causing a memory leak.

Steps to reproduce

  1. Create AsyncQueue and push items
  2. Start iterating with for await...of
  3. Break early before consuming all items
  4. Pending resolvers remain in the array indefinitely

Expected

Abandoning iteration should clean up pending resolvers.

Actual

Resolvers leak and are never garbage collected.

Environment

packages/opencode/src/util/queue.ts

Activity

  1. github-actions commented on Jul 2, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues related to AsyncQueue and memory leaks. Please check:

    If your issue describes a distinct scenario (e.g., a for await...of consumer breaking early rather than SSE-specific stalls), it may still be worth keeping open as a separate code path. But please review the above to see if they cover your case.

  2. HEETMEHTA18 commented on Jul 2, 2026

    @HEETMEHTA18
    Author

    This covers a distinct scenario from the SSE memory leaks (#22198, #31923). Those are about server-side zombie TCP connections where the server never detects client disconnect — the fix there belongs in the SSE/connection layer.

    This issue is about the general-purpose AsyncQueue having no way to clean up pending resolvers when a consumer deliberately abandons iteration (e.g. break/return from for await...of). The fix is adding a close() method so any consumer can terminate the queue cleanly.

    The two issues share the same utility class but have different root causes and different fix locations. This one is a prerequisite for any queue-level cleanup regardless of the SSE story.

  3. github-actions commented on Sep 1, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions