Skip to content

fix: reject reserved event names on public emits - #253

Merged
electrohyun merged 2 commits into
mainfrom
fix/reject-reserved-event-names
Aug 12, 2026
Merged

electrohyun merged 2 commits into
mainfrom
fix/reject-reserved-event-names

Conversation

@electrohyun

@electrohyun electrohyun commented Aug 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Smocket already kept reserved lifecycle events out of incoming and outgoing catch-all observation, but it did not protect the public send boundary itself. Application code could call emit('disconnect'), emit('connect_error'), or another reserved name on a server, namespace, broadcast operator, server socket, or client socket. The mock then treated that name as an ordinary packet: it could reach the peer, enter a disconnected client's send buffer, or fire onAnyOutgoing. Socket.IO rejects the same call before any of those effects occur.

This adds one public-emit guard for Socket.IO's six reserved names: connect, connect_error, disconnect, disconnecting, newListener, and removeListener. Ordinary emit() throws Error('"name" is a reserved event name') synchronously. emitWithAck() preserves Socket.IO's different observable shape: because upstream calls emit() inside the Promise executor, the same error becomes a rejected Promise rather than escaping synchronously. Rejection happens before delivery, buffering, acknowledgement registration, timeout creation, volatile dropping, or outgoing catch-all notification.

The guard covers the concrete send implementations rather than every delegating facade independently. Server and Namespace emissions reach BroadcastOperator, so the operator rejects names even when it has no recipients and carries the rule through room narrowing, timeout, and volatile composition. Direct server and client sockets guard their own emit paths. Their timeout and volatile views reject before they arm a timer, inspect connection state, drop a volatile packet, or invoke an outgoing listener. The failed missing-origin client keeps its intentional inert behavior for ordinary application events, but it now rejects reserved names on direct, timeout, volatile, and acknowledgement forms just like a Socket.IO client that has not connected.

Internal lifecycle delivery remains separate. Smocket continues to call its private dispatch() path for connect, connect_error, disconnecting, and disconnect, so middleware rejection, missing-server reporting, connection completion, and teardown can still emit the library-owned events. connection and new_namespace are not in the public packet reserved set and remain valid application payload names, matching the measured Socket.IO broadcast path rather than the distinct reserved-listener maps used internally by Server and Namespace.

Socket.IO reference

The runtime surface was probed independently against Socket.IO and socket.io-client 4.7.5 and 4.8.3 before the mock changed. Both supported version pairs produced the same results across Server, Namespace, BroadcastOperator, server Socket, client Socket, and their timeout or volatile forms.

Observation Socket.IO 4.7.5 and 4.8.3
Public reserved-name set connect, connect_error, disconnect, disconnecting, newListener, removeListener
Ordinary emit(reserved) synchronously throws Error('"name" is a reserved event name')
emitWithAck(reserved) returns a Promise rejected with the same Error
Peer delivery none
onAnyOutgoing not called
Timeout wrapper rejects before an acknowledgement timer is armed
Volatile wrapper rejects even when the packet would otherwise be dropped
connection and new_namespace accepted as ordinary public packet names

The probes exercised every named server surface with all six reserved names, then sent a later application marker in each direction. Once the marker arrived, neither peer had observed connect_error, and each outgoing catch-all contained only the marker. The same probe also delivered connection and new_namespace in both directions. This establishes both sides of the boundary without broadening the reserved set from a similarly named internal namespace constant.

The installed upstream sources explain the surface sharing observed by the probe. Socket.IO server sockets and broadcast operators both check the same six-name set. Server.emit() delegates to the root namespace, and namespace delivery constructs a broadcast operator. socket.io-client performs the corresponding check at the start of Socket.emit(). The implementation here follows those observable entry points while retaining Smocket's own in-memory routing and internal dispatch structure.

Rejection ordering

Ordering is part of this fix because several wrappers previously had observable work before delivery. A normal client emit notified onAnyOutgoing and then either buffered or sent. A timeout emit could create a timer before delegating. A volatile emit inspected whether the peer was connected before deciding to drop. The reserved-name check now precedes all of those branches, so a rejected call leaves no queued packet, outgoing observation, pending acknowledgement, or timeout callback behind.

The acknowledgement helper performs its guard inside the Promise executor. That placement is intentional: moving the same check into ServerSocket.emitWithAck() before constructing a Promise would produce a synchronous throw and diverge from both supported Socket.IO versions. Connected and disconnected acknowledgement paths share the helper, so a reserved name rejects consistently while an allowed disconnected volatile acknowledgement still remains pending under the existing ADR 0016 behavior.

The missing-origin FailedClientSocket follows the same boundary. Allowed events remain inert and chain as ADR 0005 records; reserved events throw, and reserved acknowledgement calls reject. This keeps the deliberate no-retry client behavior without turning it into an exception to Socket.IO's event-name rule.

Type surface

Socket.IO's declarations do not encode the runtime reserved-name rejection. An untyped default event map accepts every string, and a concrete event map that explicitly declares disconnect makes emit('disconnect') compile on the server, namespace, broadcast, server socket, client socket, timeout, and volatile surfaces. Both 4.7.5 and 4.8.3 compiled the same consumer fixture.

Smocket therefore keeps the same permissive declaration boundary instead of introducing an Exclude that would make a valid Socket.IO call site fail after substitution. The type fixture now compiles mapped disconnect calls through the equivalent Smocket and real Socket.IO generics, including client acknowledgement wrappers. Runtime tests carry the rejection guarantee; the type fixture carries the equally important fact that Smocket is not stricter than upstream where TypeScript cannot represent the runtime rule without breaking compatibility.

Tests and documentation

src/reserved-events.test.ts adds real-first coverage for all six names on every supported server and client emit shape. It pairs those invalid calls with accepted application events, covers the pending-connection window, proves non-delivery with later markers, proves outgoing catch-alls remain empty, checks the rejected-Promise acknowledgement shape, and pins connection and new_namespace as allowed packet names. src/connect-url.test.ts separately covers the terminal missing-origin client so its direct, timeout, volatile, and acknowledgement views cannot bypass the guard.

src/volatile.test.ts exercises allowed volatile.emitWithAck() calls in both directions while connected, including the outgoing catch-all that runs before delivery. Its two pre-connect marker cases also issue acknowledgement forms and prove they are dropped before the later normal marker arrives. Together these cases cover both the connected and dropped target branches without waiting for a pending acknowledgement.

docs/conformance.md is regenerated from the green dual run and records the reserved-event cases, the volatile acknowledgement case, and the failed-client Smocket case. The reserved-event entry is removed from docs/differences.md section C because #232 is no longer an accidental fidelity gap. Under ADR 0019 this is an observable correction toward measured Socket.IO behavior, which lands as the pre-1.0 patch scheduled for v0.4.3.

Locally, the Node dual run passes 446 tests across 50 files, the Chromium mock run passes 223 tests across 25 files, and the published dist run passes 192 tests across 22 files. Patch-relevant coverage now executes the connected and pre-connect branches for both server and client volatile acknowledgement paths. TypeScript, ESLint, Prettier, coverage, conformance drift, build, smoke, external-import inspection, publint, and Are the Types Wrong all pass.

Related issue

Closes #232

Checklist

  • Tests added or updated
  • Behavior verified against real socket.io

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@electrohyun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a6b9d3fe-ffcb-473f-9d15-d578de2956a3

📥 Commits

Reviewing files that changed from the base of the PR and between 6e8106b and 18ddb37.

📒 Files selected for processing (8)
  • docs/conformance.md
  • docs/differences.md
  • scripts/conformance-report.mjs
  • src/connect-url.test.ts
  • src/event-maps.typecheck.ts
  • src/mock-server.ts
  • src/reserved-events.test.ts
  • src/volatile.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug Something isn't working 📏 l Pull request changes 200–999 lines labels Aug 12, 2026
@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@electrohyun
electrohyun force-pushed the fix/reject-reserved-event-names branch from f997723 to 18ddb37 Compare August 12, 2026 08:28
@electrohyun
electrohyun merged commit f614c6a into main Aug 12, 2026
15 checks passed
@electrohyun
electrohyun deleted the fix/reject-reserved-event-names branch August 12, 2026 08:30
@electrohyun electrohyun self-assigned this Aug 12, 2026
@github-project-automation github-project-automation Bot moved this to Done in smocket Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 📏 l Pull request changes 200–999 lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix: reject reserved event names on public emit surfaces

1 participant