opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Memory leak: Uncleaned timeouts, intervals, and subscriptions

Open sauerdaniel opened this issue 15 hours ago • 1 comments

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

sauerdaniel avatar Jan 17 '26 23:01 sauerdaniel