Skip to content

fix(irc): stop background exchange poll loop on session dispose#809

Open
apoc wants to merge 1 commit intocan1357:mainfrom
apoc:fix/irc-poll-teardown-guard
Open

fix(irc): stop background exchange poll loop on session dispose#809
apoc wants to merge 1 commit intocan1357:mainfrom
apoc:fix/irc-poll-teardown-guard

Conversation

@apoc
Copy link
Copy Markdown
Contributor

@apoc apoc commented Apr 26, 2026

The 50ms retry loop in #scheduleBackgroundExchangeFlush had no guard against session teardown. If dispose() was called while streaming, the setTimeout callbacks kept firing and attempted emitExternalEvent on a disconnected agent indefinitely.

Changes

  • Add #isDisposed flag; set it synchronously at the top of dispose() before any async teardown so poll ticks that fire mid-teardown bail out cleanly
  • Clear #pendingBackgroundExchanges in dispose() to drop queued messages that will never be rendered
  • Widen the attempt() bail condition to include #isDisposed so the loop terminates even if new messages arrived between the dispose() clear and the next tick (small window during async teardown)

The 50ms retry loop in #scheduleBackgroundExchangeFlush had no guard
against session teardown. If dispose() was called while streaming,
the setTimeout callbacks kept firing and attempted emitExternalEvent
on a disconnected agent.

- Add #isDisposed flag; set it at the top of dispose() before any
  async teardown so poll ticks that fire mid-teardown bail out cleanly
- Clear #pendingBackgroundExchanges in dispose() to drop queued
  messages that will never be rendered
- Widen the attempt() bail condition to include #isDisposed so the
  loop terminates even if new messages arrived between the dispose()
  clear and the next tick
@apoc apoc force-pushed the fix/irc-poll-teardown-guard branch from e52485f to 905b8e6 Compare May 5, 2026 07:05
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