GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — Memory leak in server mode: unbounded EventTarget listeners added to Effect-ts internal emitter (QL) per session · Issue #29204 · anomalyco/opencode Closed as not planned Closed as not planned Copy link DescriptionEnvironment
SummaryWhen running Warning output (from
|
| Invocation | CPU time | Memory peak |
|---|---|---|
| 1 | 2 m 52 s | 1.1 GB |
| 2 | 2 m 19 s | 9.6 GB |
| 3 | 22 m 23 s | 2.1 GB |
| 4 | 26 s | 683 MB |
| 5 | 53 m 55 s | 4.3 GB |
| Final (before manual stop) | 37 m 57 s | 1.5 GB |
Memory peaks are non-monotone (restart clears heap) but always balloon well above baseline within minutes. The 9.6 GB spike suggests the leak compounds quickly under concurrent or long-lived sessions.
The stack points to Effect-ts's internal scheduler (runTasks / afterScheduled / evaluate). Each call to ~effect/Effect/evaluate registers a new "event" listener on an internal QL EventEmitter but does not remove it after the fiber/task completes. In server mode, each client session or SSE subscription forks new fibers, so listeners accumulate proportionally to session count.
QL is a minified class name in the compiled bundle (chunk-1h0fh6v6.js); in source it is likely Queue or a similar bounded-queue abstraction from effect/Queue or effect/Runtime.
opencode serve --hostname 0.0.0.0 --port 4096opencode attach)MaxListenersExceededWarning in stderr within ~30 sopencode serve)Find every .on("event", ...)" / .addListener("event", ...)call on the relevant Effect-ts emitter in the server session/subscription path and pair it with a corresponding.off()or.removeListener()` in the cleanup/finalizer. Alternatively, scope the emitter per session rather than sharing a singleton.
This issue might be a duplicate of existing issues. Please check:
MaxListenersExceededWarning from the same Effect-ts internal emitter (QL/iz) with the same stack trace (~effect/Effect/evaluate → runLoop → runTasks → afterScheduled) when starting the web interface/server mode.opencode serve mode, same massive memory leak with unbounded virtual memory growth — reported just hours earlier.opencode server listening on http://127.0.0.1:4096
MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 event listeners added to [MZ]. MaxListeners is undefined. Use events.setMaxListeners() to increase limit
emitter: MZ {
_events: [Object ...],
_eventsCount: 1,
_maxListeners: undefined,
[Symbol(kCapture)]: false,
emit: [Function: emit],
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
prependOnceListener: [Function: prependOnceListener],
removeListener: [Function: removeListener],
off: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
rawListeners: [Function: rawListeners],
listenerCount: [Function: listenerCount],
eventNames: [Function: eventNames],
},
type: "event",
count: 11,
at overflowWarning (node:events:185:19)
at addListener (node:events:158:22)
at ~effect/Effect/evaluate (B:/~BUN/root/chunk-yt94mfwj.js:25:4492)
at runLoop (B:/~BUN/root/chunk-yt94mfwj.js:25:2045)
at evaluate (B:/~BUN/root/chunk-yt94mfwj.js:25:1435)
at runTasks (B:/~BUN/root/chunk-yt94mfwj.js:11:35608)
at afterScheduled (B:/~BUN/root/chunk-yt94mfwj.js:11:35495)
FWIW, I keep getting the same error, but I don't have multiple clients as suggested triggers the issue by the steps to reproduce statement. What I have noticed though, is that there is some kind of automatic refresh happening on the web ui (which I notice because it sometimes messes with the scroll position on update). It could be that the memory leak / connections not cleaned up is triggered by some imperfect event handling that re-initialise connections without cleaning out the old one, likely because it (mistakenly) things the old connection is already lost or never existed or some bad assumption like that. Just going to leave the comment here in case it is useful to someone. It is frustrating to see how many times this had been reported and how long it has existed without getting resolved.
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.