Fix EventEmitter MaxListenersExceededWarning in test suite (SIGINT/SIGTERM)

Open Beginner friendly
#59 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
testing

Research direction

Start in src/lib/server/ydoc.ts by tracing getYDoc() and resetYDocForTests(), focusing on how SIGINT and SIGTERM listeners are registered and reset. Run npm run test:coverage and confirm the full test suite no longer prints MaxListenersExceededWarning messages.

Written by the indexing model from the issue text.

Description

bug help wanted

Noticed while working on #34 (PR #57) — every full test run prints:

```
(node:XXXXX) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. MaxListeners is 10.
(node:XXXXX) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. MaxListeners is 10.
```

Cause: `src/lib/server/ydoc.ts`'s `getYDoc()` calls `process.once('SIGINT', shutdown)` / `process.once('SIGTERM', shutdown)` on first access, but each test file that calls `resetYDocForTests()` and then `getYDoc()` again creates a fresh `YDocState` and registers a new pair of listeners — the old ones are never removed (`process.off`/`removeListener` is never called). Across enough test files in one Vitest worker process, this crosses Node's default max-listener warning threshold (10).

Not currently causing test failures, just console noise, but it's a real (if small) leak: harmless in a real server process (this only happens once, at real startup), but indicates resetYDocForTests() should probably also deregister the previous state's shutdown listeners, not just clear the Y.Doc/timer/audit-observer state.

Proposal

  • Track the registered shutdown listener (or make it idempotent via a stored reference) in YDocState, and remove it in resetYDocForTests() before creating a new one
  • Verify the warning is gone from a full npm run test:coverage run
Dominant language
TypeScript
Stars
1
Forks
1
Avg merge
3h 53m
Merged PRs (30d)
124

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from brylie/compendium

All issues in brylie/compendium

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.