Title: WebSocket upgrades fail intermittently under pm2: ERR_HTTP_SOCKET_ASSIGNED (@pm2/io httpMetrics vs @fastify/websocket) · Issue #545 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub
Open Graph Title: WebSocket upgrades fail intermittently under pm2: ERR_HTTP_SOCKET_ASSIGNED (@pm2/io httpMetrics vs @fastify/websocket) · Issue #545 · JavaScriptSolidServer/JavaScriptSolidServer
X Title: WebSocket upgrades fail intermittently under pm2: ERR_HTTP_SOCKET_ASSIGNED (@pm2/io httpMetrics vs @fastify/websocket) · Issue #545 · JavaScriptSolidServer/JavaScriptSolidServer
Description: Symptom On a production JSS (0.0.204, node v22.21.1, Ubuntu) running under pm2, WebSocket upgrades to /.webrtc fail in intermittent bursts. Clients see either a failed connect or — worse — a half-open socket (TLS front returns 101, but t...
Open Graph Description: Symptom On a production JSS (0.0.204, node v22.21.1, Ubuntu) running under pm2, WebSocket upgrades to /.webrtc fail in intermittent bursts. Clients see either a failed connect or — worse — a half-o...
X Description: Symptom On a production JSS (0.0.204, node v22.21.1, Ubuntu) running under pm2, WebSocket upgrades to /.webrtc fail in intermittent bursts. Clients see either a failed connect or — worse — a half-o...
Opengraph URL: https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/545
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"WebSocket upgrades fail intermittently under pm2: ERR_HTTP_SOCKET_ASSIGNED (@pm2/io httpMetrics vs @fastify/websocket)","articleBody":"## Symptom\n\nOn a production JSS (0.0.204, node v22.21.1, Ubuntu) running under pm2, WebSocket upgrades to `/.webrtc` fail in intermittent bursts. Clients see either a failed connect or — worse — a half-open socket (TLS front returns 101, but the inner upgrade has already died, so the client gets silence: no messages, no error). Fresh-socket clients (curl, Node `WebSocket`) almost always succeed; browsers holding keep-alive connections to the same host intermittently hit it.\n\n## Logs\n\n```\n{\"level\":40,\"err\":{\"type\":\"Error\",\"message\":\"ServerResponse has an already assigned socket\",\n \"stack\":\"Error [ERR_HTTP_SOCKET_ASSIGNED]: ServerResponse has an already assigned socket\n at ServerResponse.assignSocket (node:_http_server:291:11)\n at Server.onUpgrade (.../node_modules/@fastify/websocket/index.js:56:19)\n at Server.emit (node:events:531:35)\n at Server.\u003canonymous> (.../lib/node_modules/pm2/node_modules/@pm2/io/build/main/metrics/httpMetrics.js:153:37)\n at onParserExecuteCommon (node:_http_server:977:14)\",\n \"code\":\"ERR_HTTP_SOCKET_ASSIGNED\"},\"msg\":\"websocket upgrade failed\"}\n```\n\nBursts of these correlate exactly with client-observed dead signaling connections.\n\n## Analysis\n\npm2's `@pm2/io` httpMetrics instrumentation wraps the HTTP server's events and sits in the upgrade path ahead of `@fastify/websocket`'s `onUpgrade`. \"Already assigned socket\" points at upgrades arriving on **reused keep-alive sockets** (a connection that previously served a normal HTTP response), where the wrapper's ServerResponse handling collides with the upgrade's `assignSocket`. That matches the observed pattern: fresh sockets fine, browser keep-alive connections intermittent.\n\nPossibly aggravated in this deployment by a pm2 daemon/CLI version mismatch (in-memory 6.0.14 vs local 4.5.6), so the injected `@pm2/io` came from a different pm2 than the one managing the process.\n\n## Suggested directions\n\n- register the upgrade handler so it runs ahead of (or is resilient to) external 'request'/'upgrade' instrumentation — e.g. guard `onUpgrade` against an already-assigned socket and destroy/retry instead of throwing through\n- document pm2 deployment guidance for websocket-bearing instances (metrics-off configuration, or systemd as the recommended supervisor when `--webrtc`/`--tunnel`/notifications are enabled)\n- a health probe: the `/.webrtc` route could expose a trivial HTTP GET response (instead of 404) so operators can distinguish \"flag off\" from \"upgrade path broken\"\n\n## Environment\n\n- jss 0.0.204 under pm2 (fork mode), node v22.21.1\n- mitigation being applied operationally: `pm2 update` + restart; will report recurrence here","author":{"url":"https://github.com/melvincarvalho","@type":"Person","name":"melvincarvalho"},"datePublished":"2026-06-10T11:57:01Z","url":"https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/545"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ed7a57ca-0124-24b6-226e-724a3d522e19 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C34:2F9258:490038:5C5F1E:6B0389DB |
| html-safe-nonce | a581d727c3dd1fed3d7f3ccc17f0ddee728d5092e9181e82c811d798731bc277 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzM0OjJGOTI1ODo0OTAwMzg6NUM1RjFFOjZCMDM4OURCIiwidmlzaXRvcl9pZCI6IjEyNTgxOTY2NzU1MTA1MjQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a5389210c2b43ed68e67f6d9b3a20641d74fb93acde390243deab4dfc70a0c87 |
| hovercard-subject-tag | issue:4630948297 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/JavaScriptSolidServer/JavaScriptSolidServer/545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3089e89ea95d86337568434b91b5c69f74704d6539c6b26201ccbcfd49c29f81/JavaScriptSolidServer/JavaScriptSolidServer/issues/545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3089e89ea95d86337568434b91b5c69f74704d6539c6b26201ccbcfd49c29f81/JavaScriptSolidServer/JavaScriptSolidServer/issues/545 |
| og:image:alt | Symptom On a production JSS (0.0.204, node v22.21.1, Ubuntu) running under pm2, WebSocket upgrades to /.webrtc fail in intermittent bursts. Clients see either a failed connect or — worse — a half-o... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | melvincarvalho |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/JavaScriptSolidServer/JavaScriptSolidServer git https://github.com/JavaScriptSolidServer/JavaScriptSolidServer.git |
| octolytics-dimension-user_id | 205442424 |
| octolytics-dimension-user_login | JavaScriptSolidServer |
| octolytics-dimension-repository_id | 958025407 |
| octolytics-dimension-repository_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 958025407 |
| octolytics-dimension-repository_network_root_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width