Skip to content

fix: prevent memory leak in stream abort race - #223

Merged
franceccon merged 1 commit into
apibara:mainfrom
jaipaljadeja:fix/abort-promise-memory-leak
Jul 15, 2026
Merged

franceccon merged 1 commit into
apibara:mainfrom
jaipaljadeja:fix/abort-promise-memory-leak

Conversation

@jaipaljadeja

Copy link
Copy Markdown
Member

Closes #222

  • Create a fresh abort promise for each stream.next() call.
  • Remove the abort listener as soon as either side of the race settles.
  • Recheck the signal after registering the listener to handle an already-aborted signal.

This prevents promise reactions and decoded message buffers from accumulating on a long-lived pending abort promise.

This update introduces a new `nextWithAbort` function to manage abort signals more effectively during stream reads. The previous implementation of abort handling has been removed to streamline the code and prevent potential issues with long-lived promises. The new approach ensures that the abort listener is properly removed after use, enhancing the overall reliability of the stream processing logic.
@jaipaljadeja
jaipaljadeja requested a review from franceccon July 14, 2026 21:23

@franceccon franceccon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@franceccon
franceccon merged commit 0993bbf into apibara:main Jul 15, 2026
0 of 2 checks passed
@ShubhamChndrvnshi

Copy link
Copy Markdown

noice 🚀

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.

Indexer run loop leaks memory by reusing a pending abort Promise

3 participants