Skip to content

fix: reconstruct corrupted server.js message pipeline - #218

Merged
levibliz merged 2 commits into
RiftCore00:mainfrom
ayomidemariam:fix/reconstruct-server-js
Jul 30, 2026
Merged

fix: reconstruct corrupted server.js message pipeline#218
levibliz merged 2 commits into
RiftCore00:mainfrom
ayomidemariam:fix/reconstruct-server-js

Conversation

@ayomidemariam

Copy link
Copy Markdown
Contributor

Summary

Reconstructs the fatally corrupted src/server.js which had duplicate wss declarations causing SyntaxError: Identifier 'wss' has already been declared, preventing 6 test suites from loading.

Root Cause

The upstream server.js contained two interleaved implementations merged incorrectly:

  • First const wss = new WebSocketServer(...) on line 31 bound to server
  • Second const wss = new WebSocketServer({ noServer: true }) on line 53
  • Two HTTP server instances (server and httpServer)
  • clearInterval(interval) referencing undefined variable (should be heartbeatInterval)
  • Missing createRateLimiter import and safeSend function

Changes

  • Removed duplicate declarations: Single const wss bound to httpServer
  • Merged HTTP endpoints: Supports /health (returns { status: "OK" }) and /healthz (returns { status: "ok", uptime }) for backward compatibility
  • Added /readyz readiness endpoint with connection/room counts
  • Added /metrics Prometheus-format endpoint tracking connections, messages, auth failures, heap usage
  • Added markShuttingDown() method for graceful shutdown (503 responses)
  • Restored safeSend wrapper for error-safe WebSocket sends
  • Restored per-message rate limiting via createRateLimiter import
  • Fixed clearInterval referencing correct heartbeatInterval variable
  • Added per-IP connection tracking with configurable maxConnectionsPerIp
  • Returns { wss, httpServer, rooms, markShuttingDown } supporting both wss.address() and httpServer.address() patterns

Verification

  • All 20 test files pass (178 tests passed, 15 skipped for postgres)
  • Lint passes with zero errors
  • No existing test files modified

Closes #191

ayomidemariam and others added 2 commits July 27, 2026 18:45
- Remove duplicate wss and httpServer declarations causing SyntaxError
- Merge two scrambled implementations into single coherent createServer
- Add /health and /healthz endpoints returning JSON responses
- Add /readyz readiness endpoint with connection/room counts
- Add /metrics Prometheus endpoint tracking connections, messages, auth
- Add markShuttingDown() for graceful shutdown support
- Restore safeSend wrapper for error-safe WebSocket sends
- Restore per-message rate limiting via createRateLimiter import
- Fix clearInterval referencing undefined 'interval' variable
- Add per-IP connection count tracking with configurable max
- Return { wss, httpServer, rooms, markShuttingDown }
- All 178 tests pass, lint clean

Closes RiftCore00#191
@levibliz
levibliz merged commit 7582352 into RiftCore00:main Jul 30, 2026
RajeshRk18 pushed a commit to RajeshRk18/Real-Time-Spatial-Tracking-Gateway that referenced this pull request Aug 18, 2026
…nto feat/session-resumption-228

Resolves conflicts with the independently merged session-resumption
implementation (RiftCore00#267) and the co-located HTTP server / backpressure
work (RiftCore00#203, RiftCore00#217, RiftCore00#218):

- src/session-manager.js: keep this branch's encrypted manager
  (AES-256-GCM + HKDF, Redis/in-memory store, debounced saves, metrics)
  over the add/add conflicting upstream variant.
- src/server.js: keep this branch's session wiring and admin migration
  endpoint; integrate upstream's /healthz, /readyz and Prometheus
  /metrics endpoints, gateway metrics counters, event-loop lag sampling
  and markShuttingDown. Session resumption counters are now exported in
  the Prometheus exposition instead of a JSON /metrics body.
- src/index.js: keep session-aware graceful shutdown; call
  markShuttingDown() on SIGTERM/SIGINT so health probes flip to 503.
- src/room-manager.js: keep ring-buffer replay/dedup/limits; restore the
  backpressure-aware broadcast wiring (constructor options, client
  state tracking and cleanup) that upstream's copy referenced but never
  initialized.
- tests: keep this branch's session-manager and resumption integration
  suites; update /metrics assertions to the Prometheus format.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uUSA8xm8WNue2Cw1mj1zM
RajeshRk18 added a commit to RajeshRk18/Real-Time-Spatial-Tracking-Gateway that referenced this pull request Aug 18, 2026
…nto feat/session-resumption-228

Resolves conflicts with the independently merged session-resumption
implementation (RiftCore00#267) and the co-located HTTP server / backpressure
work (RiftCore00#203, RiftCore00#217, RiftCore00#218):

- src/session-manager.js: keep this branch's encrypted manager
  (AES-256-GCM + HKDF, Redis/in-memory store, debounced saves, metrics)
  over the add/add conflicting upstream variant.
- src/server.js: keep this branch's session wiring and admin migration
  endpoint; integrate upstream's /healthz, /readyz and Prometheus
  /metrics endpoints, gateway metrics counters, event-loop lag sampling
  and markShuttingDown. Session resumption counters are now exported in
  the Prometheus exposition instead of a JSON /metrics body.
- src/index.js: keep session-aware graceful shutdown; call
  markShuttingDown() on SIGTERM/SIGINT so health probes flip to 503.
- src/room-manager.js: keep ring-buffer replay/dedup/limits; restore the
  backpressure-aware broadcast wiring (constructor options, client
  state tracking and cleanup) that upstream's copy referenced but never
  initialized.
- tests: keep this branch's session-manager and resumption integration
  suites; update /metrics assertions to the Prometheus format.
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.

2 participants