Skip to content

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

Open
ayomidemariam wants to merge 1 commit into
RiftCore00:mainfrom
ayomidemariam:fix/reconstruct-server-js
Open

fix: reconstruct corrupted server.js message pipeline#218
ayomidemariam wants to merge 1 commit into
RiftCore00:mainfrom
ayomidemariam:fix/reconstruct-server-js

Conversation

@ayomidemariam

Copy link
Copy Markdown

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

- 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
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