Skip to content

fix: set explicit HTTP timeouts to prevent OOM when network is blocked#1005

Closed
msmolkin wants to merge 2 commits into
steipete:mainfrom
msmolkin:fix/cli-http-timeout
Closed

fix: set explicit HTTP timeouts to prevent OOM when network is blocked#1005
msmolkin wants to merge 2 commits into
steipete:mainfrom
msmolkin:fix/cli-http-timeout

Conversation

@msmolkin
Copy link
Copy Markdown

Summary

  • Set timeoutIntervalForRequest = 30s and timeoutIntervalForResource = 90s on ProviderHTTPClient's URLSession
  • Set waitsForConnectivity = false so blocked connections fail immediately instead of waiting

Problem

URLSession.shared defaults to timeoutIntervalForResource = 604800 (7 days). When a firewall blocks CodexBarCLI (e.g. LuLu on macOS blocks unsigned/new CLI binaries by default), every provider fetch hangs indefinitely. With the usage command spawning concurrent tasks for all enabled providers, the process accumulates 28 GB+ of memory per instance, triggering Jetsam and crashing the system.

Observed on v0.26.1 with LuLu firewall on macOS 15. Two stuck CodexBarCLI processes totaling 56 GB crashed the machine.

Fix

One-line change to ProviderHTTPClient.init: use a custom URLSessionConfiguration with sane timeouts instead of URLSession.shared.

Fixes #1004

Test plan

  • Run codexbar usage with network blocked → should fail within 30s with timeout error instead of hanging
  • Run codexbar usage with network allowed → should work as before
  • Existing tests pass (timeout doesn't affect normal response times)

…s blocked

URLSession.shared defaults to timeoutIntervalForResource = 604800s (7 days).
When a firewall (LuLu, Little Snitch) blocks CodexBarCLI's network access,
requests hang indefinitely while the process accumulates memory — observed
28 GB per CLI instance, triggering Jetsam and crashing the system.

Set timeoutIntervalForRequest = 30s and timeoutIntervalForResource = 90s
with waitsForConnectivity = false so blocked connections fail fast instead
of hanging for a week.

Fixes steipete#1004
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e295faf1f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30
configuration.timeoutIntervalForResource = 90
configuration.waitsForConnectivity = false
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard waitsForConnectivity for FoundationNetworking

On Linux builds of the unconditional CodexBarCore/CodexBarCLI targets, URLSessionConfiguration comes from FoundationNetworking, where waitsForConnectivity is get-only; compiling this file fails with cannot assign to property: 'waitsForConnectivity' is a get-only property. The macOS-only behavior is fine, but this assignment needs a platform guard or another cross-platform timeout-only path so the Linux targets/tests continue to build.

Useful? React with 👍 / 👎.

@steipete
Copy link
Copy Markdown
Owner

Thanks for the report and patch. I landed a maintainer-polished version on main as 3ce4101.

Changes before landing:

  • Kept the shared ProviderHTTPClient timeout fix.
  • Preserved injected URLSession behavior for tests/custom transports.
  • Added a regression test for the default client configuration.
  • Added changelog coverage.

Proof:

  • swift test --filter ProviderHTTPClientTests
  • make check
  • codex-review clean: no accepted/actionable findings reported

Co-authored-by credit preserved in the landed commit. Thank you.

@steipete steipete closed this May 17, 2026
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.

CodexBarCLI: catastrophic memory leak when network is blocked (28 GB per process)

2 participants