Memory leak: Uncleaned timeouts, intervals, and subscriptions #6638

Open
opened 2026-02-16 18:04:49 -05:00 by yindo · 2 comments
Owner

Originally created by @sauerdaniel on GitHub (Jan 17, 2026).

Originally assigned to: @rekram1-node on GitHub.

Problem

Several small memory leaks exist across the codebase from uncleaned timeouts, intervals, and event subscriptions:

WebFetch Timeout (webfetch.ts)

When fetch throws an error, the timeout is not cleared:

const timeout = setTimeout(...)
try {
  const response = await fetch(...)
} catch (error) {
  // timeout still running!
  throw error
}

Models setInterval (models.ts)

A setInterval is created for model refresh but never cleared:

// Interval runs forever, even after module unload
setInterval(() => refreshModels(), 60000)

Bus.subscribe (github.ts)

The unsubscribe function returned by Bus.subscribe() is not captured:

// Subscription can never be unsubscribed
Bus.subscribe(Event, handler)

Impact

  • Timeouts continue running after errors
  • Intervals run indefinitely
  • Subscriptions cannot be cleaned up

Relates to #5363

Expected Behavior

  • Timeouts should be cleared in finally blocks
  • Intervals should be cleared on process exit
  • Subscription unsubscribe functions should be captured
Originally created by @sauerdaniel on GitHub (Jan 17, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem Several small memory leaks exist across the codebase from uncleaned timeouts, intervals, and event subscriptions: ### WebFetch Timeout (`webfetch.ts`) When fetch throws an error, the timeout is not cleared: ```typescript const timeout = setTimeout(...) try { const response = await fetch(...) } catch (error) { // timeout still running! throw error } ``` ### Models setInterval (`models.ts`) A setInterval is created for model refresh but never cleared: ```typescript // Interval runs forever, even after module unload setInterval(() => refreshModels(), 60000) ``` ### Bus.subscribe (`github.ts`) The unsubscribe function returned by `Bus.subscribe()` is not captured: ```typescript // Subscription can never be unsubscribed Bus.subscribe(Event, handler) ``` ### Impact - Timeouts continue running after errors - Intervals run indefinitely - Subscriptions cannot be cleaned up Relates to #5363 ## Expected Behavior - Timeouts should be cleared in finally blocks - Intervals should be cleared on process exit - Subscription unsubscribe functions should be captured
yindo added the perf label 2026-02-16 18:04:49 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 17, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9157: Memory leak: Instance disposal doesn't clean up plugins or cached resources
  • #9155: Memory leak: TUI and Slack bot event listeners not cleaned up
  • #9154: Memory leak: ACP session event streams never aborted
  • #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation
  • #9151: Memory leak (general report with Windows platform affected)
  • #9143: LSP client diagnostics and files maps not cleared on shutdown
  • #9140: Unbounded caches cause memory growth over time
  • #9136: fix(test): prevent memory and resource leaks in test infrastructure
  • #5363: opencode eating 70gb of memory? (related issue mentioned in your issue)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 17, 2026): This issue might be a duplicate of existing issues. Please check: - #9157: Memory leak: Instance disposal doesn't clean up plugins or cached resources - #9155: Memory leak: TUI and Slack bot event listeners not cleaned up - #9154: Memory leak: ACP session event streams never aborted - #9153: Memory leak: MCP OAuth transports not closed on retry or cancellation - #9151: Memory leak (general report with Windows platform affected) - #9143: LSP client diagnostics and files maps not cleared on shutdown - #9140: Unbounded caches cause memory growth over time - #9136: fix(test): prevent memory and resource leaks in test infrastructure - #5363: opencode eating 70gb of memory? (related issue mentioned in your issue) Feel free to ignore if none of these address your specific case.
Author
Owner

@sauerdaniel commented on GitHub (Feb 16, 2026):

Status: fix is implemented in PR #9148. Remaining blocker is CI on e2e (windows) (NotFoundError), which cascades to the linux gate.

@sauerdaniel commented on GitHub (Feb 16, 2026): Status: fix is implemented in PR #9148. Remaining blocker is CI on `e2e (windows)` (`NotFoundError`), which cascades to the linux gate.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6638