{"record":{"id":"c9bf22579c98fe4c","repo":"facebook/react","slug":"only-one-connection-allowed-at-a-time-closing-the","errorCode":null,"errorMessage":"Only one connection allowed at a time. Closing the previous connection","messagePattern":"Only one connection allowed at a time\\. Closing the previous connection","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/react-devtools-core/src/standalone.js","lineNumber":347,"sourceCode":"  port: number = 8097,\n  host: string = 'localhost',\n  httpsOptions?: ServerOptions,\n  loggerOptions?: LoggerOptions,\n  path?: string,\n  clientOptions?: ClientOptions,\n): {close(): void} {\n  registerDevToolsEventLogger(loggerOptions?.surface ?? 'standalone');\n\n  const useHttps = !!httpsOptions;\n  const httpServer = useHttps\n    ? require('https').createServer(httpsOptions)\n    : require('http').createServer();\n  const server = new Server({server: httpServer, maxPayload: 1e9});\n  let connected: WebSocket | null = null;\n  server.on('connection', (socket: WebSocket) => {\n    if (connected !== null) {\n      connected.close();\n      log.warn(\n        'Only one connection allowed at a time.',\n        'Closing the previous connection',\n      );\n    }\n    connected = socket;\n    socket.onerror = error => {\n      connected = null;\n      onDisconnected();\n      log.error('Error with websocket connection', error);\n    };\n    socket.onclose = () => {\n      connected = null;\n      onDisconnected();\n      log('Connection to RN closed');\n    };\n    initialize(socket);\n  });\n","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-devtools-core/src/standalone.js#L329-L365","documentation":"react-devtools-core's standalone entry point (used by the DevTools shell and React Native DevTools) hosts a WebSocket server that supports exactly one active frontend: the module-level `connected` variable holds the single socket. When a new client connects, the previous socket is closed and log.warn prints 'Only one connection allowed at a time. Closing the previous connection'. The behavior is intentional — DevTools is a single-client tool — but the displaced client sees onDisconnected fire and loses its DevTools link.","triggerScenarios":"A second WebSocket client connecting to the standalone server (new Server({server, maxPayload: 1e9})) while a previous one is still registered as `connected`: a second browser tab, a second DevTools shell, or a reconnect that lands before the old socket's onclose cleared the slot.","commonSituations":"Running `npx react-devtools` and pointing two tabs at the same port; editor-embedded React Native DevTools plus a browser DevTools on the same server; e2e/CI harnesses that leave sockets half-open; rapid reconnect loops.","solutions":["Use exactly one DevTools frontend per standalone server: close the previous tab/window before connecting another.","If you truly need two clients, run a second standalone server on a different port (e.g. react-devtools --port=8098).","Handle onDisconnected in the embedding app so a takeover is shown in the UI instead of a silently dead panel.","Make clients close their socket on page unload so stale connections do not hold the slot."],"exampleFix":"# before: two frontends -> one server (first tab gets kicked)\nnpx react-devtools  # ws://localhost:8097\n\n# after: one server per client\nnpx react-devtools --port=8097\nnpx react-devtools --port=8098","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Connect exactly one DevTools frontend per standalone server; close the previous client first.","Run additional standalone servers on distinct ports for additional clients.","Close the WebSocket on page unload so stale connections do not occupy the single slot.","If you are the displaced client, reconnect (with backoff) once the other client disconnects — onDisconnected signals the takeover."],"tags":["react-devtools","websocket","standalone","connection"],"backgroundTag":"single-connection-limit","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}