Skip to content

fix: raise default maxListeners to suppress benign gz stream warning#285

Merged
BYK merged 1 commit into
mainfrom
fix/max-listeners-warning
May 13, 2026
Merged

fix: raise default maxListeners to suppress benign gz stream warning#285
BYK merged 1 commit into
mainfrom
fix/max-listeners-warning

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 13, 2026

Summary

  • Raises events.defaultMaxListeners from 10 to 15 in packages/gateway/instrument.ts to eliminate a benign MaxListenersExceededWarning that fires once per OpenCode session.

Root Cause

When the gateway runs in-process inside OpenCode (Bun), upstream fetch() calls receive gzip-compressed responses. Bun's internal fetch creates a zlib.Gunzip transform stream, and the Web Streams adapter + OpenCode's Effect-TS runtime attach 11 listeners to it — 1 above the default limit of 10.

Logs confirm this is not a leak: exactly 1 warning per process (4 occurrences across 4 PIDs over a week), always exactly 11 listeners, never growing. All listeners are cleaned up when the response body is consumed.

Fix

Two lines at the top of instrument.ts:

import { setMaxListeners } from "node:events";
setMaxListeners(15);

15 is still low enough to catch real leaks (which grow to hundreds).

Bun's internal fetch creates a zlib.Gunzip stream for gzip-compressed
upstream responses. The Web Streams adapter + OpenCode's Effect-TS
runtime attach 11 listeners (1 above the default limit of 10),
triggering a one-time MaxListenersExceededWarning per process. Raise
the process-wide default to 15 — still low enough to catch real leaks.
@BYK BYK merged commit 53e789e into main May 13, 2026
7 checks passed
@BYK BYK deleted the fix/max-listeners-warning branch May 13, 2026 10:32
This was referenced May 13, 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.

1 participant