GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(memory): Fix timeout, interval, and subscription cleanup by sauerdaniel · Pull Request #9148 · anomalyco/opencode

Conversation

@sauerdaniel

@sauerdaniel sauerdaniel commented Jan 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Fix various small memory leaks from uncleaned timeouts, intervals, and event subscriptions across the codebase.

Fixes #9156

Problems

1. WebFetch Timeout (webfetch.ts)

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

2. Models setInterval (models.ts)

A setInterval is created but never cleared, even when the module is unloaded.

3. Bus.subscribe Return Value (github.ts)

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

Solution

WebFetch - Use try/finally

const timeout = setTimeout(...)
try {
  const response = await fetch(...)
  return response
} finally {
  clearTimeout(timeout)
}

Models - Track interval for cleanup

const intervalId = setInterval(...)
process.on("exit", () => clearInterval(intervalId))

Bus.subscribe - Capture unsubscribe

Store the unsubscribe function for later cleanup.

Changes

  • packages/opencode/src/util/webfetch.ts - Clear timeout in finally block
  • packages/opencode/src/provider/models.ts - Add interval cleanup on exit
  • packages/opencode/src/github/github.ts - Capture Bus.subscribe return value

Testing

  • TypeScript compilation passes (bun turbo typecheck)
  • Unit tests pass (725 tests, 0 failures)

Note: Manual testing of timeout/interval cleanup requires runtime verification which was not performed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added the needs:issue label Jan 17, 2026
@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. fix(memory): Fix event listener leaks in TUI and Slack bot #9147 - "fix(memory): Fix event listener leaks in TUI and Slack bot"

    • Related memory cleanup fix, likely part of same cleanup initiative
  2. fix(acp): Fix memory leak in session event streams #9146 - "fix(acp): Fix memory leak in session event streams"

    • Related memory leak fix in event streams
  3. fix(mcp): Fix memory leaks in OAuth transport and process cleanup #9145 - "fix(mcp): Fix memory leaks in OAuth transport and process cleanup"

    • Related memory leak fixes across the codebase
  4. fix(core): add dispose functions to prevent subscription memory leaks #7914 - "fix(core): add dispose functions to prevent subscription memory leaks"

    • Addresses subscription cleanup similar to PR fix(memory): Fix timeout, interval, and subscription cleanup #9148's Bus.subscribe fix
  5. fix(core): add dispose functions to prevent subscription memory leaks #7032 - "fix(core): add dispose functions to prevent subscription memory leaks"

    • Previous attempt at addressing subscription memory leaks
  6. Add timeout for file watcher subscribe to address hangs on Rosetta x86 emulation #5350 - "Add timeout for file watcher subscribe to address hangs on Rosetta x86 emulation"

    • Related to timeout handling

These appear to be part of a broader memory leak cleanup effort (related to issue #5363 mentioned in the PR). PRs #9145, #9146, and #9147 are particularly close in scope and timing, suggesting they may be related fixes across different modules. Consider checking if any of these address the same files or can be consolidated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:issue label Jan 17, 2026
@github-actions github-actions Bot mentioned this pull request Jan 24, 2026
fix(opencode): memory leaks in session handling #10392
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:49
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch 3 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
@sauerdaniel
sauerdaniel force-pushed the pr/memory-misc branch from 363c774 to f4e9a5a Compare February 10, 2026 19:47
@sauerdaniel

sauerdaniel commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest dev and resolved merge conflicts.\n\nChanges:\n- webfetch.ts: Combined Cloudflare retry logic with try/finally timeout cleanup\n- models.ts: Added start/stop refresh interval functions with exit handler\n- github.ts: Auto-merged successfully\n\nAll typechecks pass. Ready for review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sauerdaniel
sauerdaniel force-pushed the pr/memory-misc branch 3 times, most recently from ab4a7f3 to d1a7181 Compare February 13, 2026 13:54
@github-actions github-actions Bot mentioned this pull request Feb 13, 2026
fix: resolve multiple memory leaks causing unbounded RAM growth ( Now passing: && Fixed failing tests for windows ) #13514
Closed
@sauerdaniel
sauerdaniel force-pushed the pr/memory-misc branch 4 times, most recently from d33aec5 to 0d93111 Compare February 16, 2026 11:06
@sauerdaniel

sauerdaniel commented Feb 16, 2026

Copy link
Copy Markdown
Contributor Author

Status update: implementation is complete and linked issue coverage remains intact (Fixes #9156).

Current blocker is CI only:

  • e2e (windows) fails with repeated NotFoundError
  • test (linux) then fails on the upstream gate because e2e is red

No new code changes pending on this PR right now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sauerdaniel sauerdaniel mentioned this pull request Feb 16, 2026
Memory leak: Uncleaned timeouts, intervals, and subscriptions #9156
Closed
@sauerdaniel
sauerdaniel force-pushed the pr/memory-misc branch from 0d93111 to 415c8b4 Compare February 20, 2026 13:38
sauerdaniel added 3 commits February 20, 2026 14:38
@sauerdaniel
fix(webfetch): Clear timeout if fetch throws an error
2877638
Prevent memory leak in webfetch tool when fetch fails before timeout
triggers. Ensures timeout handle is properly cleared on all exit paths.
@sauerdaniel
fix(provider): Add cleanup mechanism for models.ts setInterval
0e44c22
Clear setInterval timer on shutdown to prevent memory leak from
orphaned interval callback references.
@sauerdaniel
fix: Capture Bus.subscribe unsubscribe function to prevent memory leak
6424df7
Store and call unsubscribe function returned by Bus.subscribe to
properly clean up event handlers when no longer needed.
@sauerdaniel
sauerdaniel force-pushed the pr/memory-misc branch from 415c8b4 to 6424df7 Compare February 20, 2026 13:39
This was referenced Feb 22, 2026
fix: cleanup SDK event listeners to prevent memory leaks #14635
Closed
fix: resolve memory leak issues across multiple subsystems #14650
Closed
@binarydoubling binarydoubling mentioned this pull request Mar 9, 2026
Multiple memory leaks cause unbounded RAM growth during extended TUI usage #16697
Closed
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Memory leak: Uncleaned timeouts, intervals, and subscriptions

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@sauerdaniel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.