Title: fix(debug-ios): make the CDP proxy pick a free port and survive reconnects by rigor789 · Pull Request #6177 · NativeScript/nativescript-cli · GitHub
Open Graph Title: fix(debug-ios): make the CDP proxy pick a free port and survive reconnects by rigor789 · Pull Request #6177 · NativeScript/nativescript-cli
X Title: fix(debug-ios): make the CDP proxy pick a free port and survive reconnects by rigor789 · Pull Request #6177 · NativeScript/nativescript-cli
Description: What is the current behavior? Port in use: isPortAvailable checks localhost, but since #5788 the WebSocket server binds every interface. On macOS those don't conflict, so a taken port passes the check, the listen fails with EADDRINUSE, and the CLI crashes. Two ns debug sessions are enough to hit it. Reconnects: the connection lock was released on the connection event, which never fires for a client that drops during the handshake. proper-lockfile keeps refreshing a lock while its process lives, so it never goes stale, and every later client fails after about 10 seconds with Timeout while waiting for lock and a 401 until the CLI exits. Separately, a late close from a replaced client could destroy the socket its successor had just received. What is the new behavior? isPortAvailable tests 127.0.0.1, ::1, 0.0.0.0 and ::, and the proxy moves to the next port if the bind still fails. Android's debug port uses the same check. Connections go through an in-process queue instead of a file lock. Each session only cleans up after itself. The newest client takes over, and the previous one is closed with Replaced by a newer debugger client. Port service timers are now cleared. The typeof timer === "number" check never matched in Node, which produced false not able to get inspector socket port warnings. The proxy only listens on 127.0.0.1 and ::1, and rejects browser origins other than DevTools and localhost with a 403. It used to accept connections from the network and from any web page, and the debugger can run any code in the app. Clients without an origin, like VS Code's debug adapter, are still accepted. Only one client at a time is supported, as before. The runtime serves a single frontend and ios-device-lib keeps one forwarded connection per device. Testing Stress test against a real app on an iOS 26.2 simulator, 5 rounds per scenario: Scenario Old proxy This PR Connect, reconnect, killed client, refresh overlap, takeover 5/5 each 5/5 each Client drops during handshake 0/5 5/5 5 clients connect at once 0/5 5/5, exactly one left connected With another process on 41000, this PR came up on 41001. Unit tests are included. On an iPad, every scenario passed until the app stopped responding 80–140 seconds into a run, then every connection got a 401. It happened in 3 of 4 runs, varied in timing, hit a plain connect/close loop too, and left no crash report. The iPad locking is the likely cause, but that isn't proven, and recovery after waking wasn't tested. Security checks against the running proxy: 127.0.0.1, ::1 and localhost connect, a https://evil.example origin gets a 403, and the machine's LAN address is refused. Real Chrome DevTools sends devtools://devtools, captured from a headless Chrome, which is on the allowed list. A full DevTools session through the proxy and VS Code's debug adapter weren't run. The Safari --inspector TCP proxy is a separate path and is unchanged. Part of a stack Base: #6176. Next: #6178. Summary by CodeRabbit Bug Fixes Improved iOS debugger connections during client reconnections and disconnects, helping keep the active session stable and recover from interrupted handshakes. Improved handling of occupied ports so the debugger can retry on another port when available. Improved port availability checks across common network addresses, reducing incorrect reports that a port is free. Restricted debugger connections to supported origins and loopback addresses, while continuing to allow valid DevTools connections. Improved handling of simultaneous clients and session replacements to prevent an old connection from disrupting the active session.
Open Graph Description: What is the current behavior? Port in use: isPortAvailable checks localhost, but since #5788 the WebSocket server binds every interface. On macOS those don't conflict, so a taken port passes th...
X Description: What is the current behavior? Port in use: isPortAvailable checks localhost, but since #5788 the WebSocket server binds every interface. On macOS those don't conflict, so a taken port passe...
Opengraph URL: https://github.com/NativeScript/nativescript-cli/pull/6177
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2907e4fb-7366-2aed-4cf0-65eb2bd9640c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DD08:2BE220:173B43B:1F06103:6B014422 |
| html-safe-nonce | 7756789dab4eb69ebdb3ce6c13f8d78d5535ff0342498ee4aafa317d31ddd277 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDA4OjJCRTIyMDoxNzNCNDNCOjFGMDYxMDM6NkIwMTQ0MjIiLCJ2aXNpdG9yX2lkIjoiNTgxMjQzMTcxOTM4MjQ2NzYxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5820feefef94fb21ec7192e012f3f9e4d7ac95ac6db72da2af5c93af321bda69 |
| hovercard-subject-tag | pull_request:5087898790 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/NativeScript/nativescript-cli/pull/6177/files |
| twitter:image | https://avatars.githubusercontent.com/u/879060?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/879060?s=400&v=4 |
| og:image:alt | What is the current behavior? Port in use: isPortAvailable checks localhost, but since #5788 the WebSocket server binds every interface. On macOS those don't conflict, so a taken port passes th... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/nativescript-cli git https://github.com/NativeScript/nativescript-cli.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 21347346 |
| octolytics-dimension-repository_nwo | NativeScript/nativescript-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21347346 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/nativescript-cli |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width