Skip to content

Harden server startup and live-mode WebSocket behavior#1

Open
Popidge wants to merge 1 commit into
v2from
codex/review-code-for-correctness-and-maintainability
Open

Harden server startup and live-mode WebSocket behavior#1
Popidge wants to merge 1 commit into
v2from
codex/review-code-for-correctness-and-maintainability

Conversation

@Popidge
Copy link
Copy Markdown
Owner

@Popidge Popidge commented Apr 22, 2026

Motivation

  • Improve reliability when starting the tester server in environments where the requested port may be taken.
  • Reduce chances of silent failures or crashes from malformed requests and WebSocket errors.
  • Make the Vite plugin and frontend live-mode behavior more robust and predictable across non-default ports and developer workflows.

Description

  • Replace brittle server.listen(...callback...) handling with event-driven listening/error logic and a configurable maxPort retry range by introducing listenOnPort and normalizing numeric port parsing.
  • Add lightweight API hardening by limiting JSON body size (express.json({ limit: '100kb')), validating POST /api/share payloads, and exposing a GET /api/config endpoint with runtime metadata.
  • Improve WebSocket robustness by installing a top-level wss.on('error') handler and safer broadcast logic to avoid unhandled crashes.
  • Update the Vite plugin to only run in serve mode, set Cache-Control: no-store on the injected shim to avoid stale config, and ensure the tester server is stopped when Vite shuts down.
  • Revamp frontend live-mode logic to try same-origin WebSocket first (supports non-default/fallback ports), fall back to legacy :3001, deduplicate URLs, and add explicit reconnect control via shouldReconnectRef with startLiveMode/disconnectWebSocket helpers.

Testing

  • Built the UI with npm run build, which completed successfully.
  • Performed a server lifecycle smoke test by starting and stopping the server programmatically with a one-liner script that created new WebShareTesterServer({ port: 3101, maxPort: 3103 }), which started and stopped successfully.
  • Verified port-collision fallback by binding a blocker to 3201 and starting the server with { port: 3201, maxPort: 3203 }, which logged the port busy message and successfully fell back to 3202.

Codex Task

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • main

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 06624233-4296-427f-8075-f46a52b10b63

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/review-code-for-correctness-and-maintainability

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 and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant