Skip to content

Commit 3deb552

Browse files
authored
fix: Dev server fixes (#8211)
🎉 Thanks for submitting a pull request! 🎉 #### Summary * Remove listeners on failure to prevent leak * Improve logging when running with`skipWaitPort` ``` BEFORE =========== ⬥ Setting up local dev server ⬥ Starting #custom dev server ⠋ Waiting for #custom dev server to be ready on port 19876 ✔ #custom dev server ready on port 19876 ← misleading ╭──────────────────────── ⬥ ────────────────────────╮ │ Local dev server ready: http://localhost:28888 │ ╰────────────────────────────────────────────────────╯ (node:67259) MaxListenersExceededWarning: ... 26 aborted listeners added to [IncomingMessage] (node:67259) MaxListenersExceededWarning: ... 26 error listeners added to [IncomingMessage] AFTER ============ ⬥ Setting up local dev server ⬥ Starting #custom dev server ⠋ Waiting for #custom dev server to be ready on port 19876 ╭──────────────────────── ⬥ ────────────────────────╮ │ Local dev server ready: http://localhost:28888 │ ╰────────────────────────────────────────────────────╯ ``` --- For us to review and ship your PR efficiently, please perform the following steps: - [ ] Open a [bug/issue](https://github.com/netlify/cli/issues/new/choose) before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you\`re fixing a typo or something that\`s on fire 🔥 (e.g. incident related), you can skip this step. - [ ] Read the [contribution guidelines](../CONTRIBUTING.md) 📖. This ensures your code follows our style guide and passes our tests. - [ ] Update or add tests (if any source code was changed or added) 🧪 - [ ] Update or add documentation (if features were changed or added) 📝 - [ ] Make sure the status checks below are successful ✅ **A picture of a cute animal (not mandatory, but encouraged)**
1 parent 0daf8ea commit 3deb552

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/utils/framework-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const startFrameworkServer = async function ({
5454
// default ip version based on node version
5555
const ipVersion = parseInt(process.versions.node.split('.')[0]) >= 18 ? 6 : 4
5656
port = { open: true, ipVersion }
57+
stopSpinner({ spinner })
5758
} else {
5859
const waitPortPromise = waitPort(
5960
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -81,8 +82,8 @@ export const startFrameworkServer = async function ({
8182
if (!port.open) {
8283
throw new Error(`Timed out waiting for port '${settings.frameworkPort}' to be open`)
8384
}
85+
spinner.success(`${settings.framework || 'framework'} dev server ready on port ${settings.frameworkPort}`)
8486
}
85-
spinner.success(`${settings.framework || 'framework'} dev server ready on port ${settings.frameworkPort}`)
8687
} catch (error_) {
8788
stopSpinner({ error: true, spinner })
8889
log(NETLIFYDEVERR, `Netlify Dev could not start or connect to localhost:${settings.frameworkPort}.`)

src/utils/proxy.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ const initializeProxy = async function ({
546546
options.target = `http://${isIPv6(newHost) ? `[${newHost}]` : newHost}:${targetUrl.port}`
547547
options.targetHostname = newHost
548548
options.isChangingTarget = true
549+
// http-proxy attaches new 'aborted'/'error' listeners on req for every proxy.web call; without
550+
// clearing them first, retries leak listeners and the closures retain per-attempt proxyReq objects.
551+
req.removeAllListeners('aborted')
552+
req.removeAllListeners('error')
549553
proxy.web(req, res, options)
550554
return
551555
}
@@ -619,6 +623,10 @@ const initializeProxy = async function ({
619623
if (req.alternativePaths && req.alternativePaths.length !== 0) {
620624
// @ts-expect-error TS(2339) FIXME: Property 'alternativePaths' does not exist on type... Remove this comment to see the full error message
621625
req.url = req.alternativePaths.shift()
626+
// http-proxy attaches new 'aborted'/'error' listeners on req for every proxy.web call; without
627+
// clearing them first, retries leak listeners and the closures retain per-attempt proxyReq objects.
628+
req.removeAllListeners('aborted')
629+
req.removeAllListeners('error')
622630
// @ts-expect-error TS(2339) FIXME: Property 'proxyOptions' does not exist on type 'In... Remove this comment to see the full error message
623631
proxy.web(req, res, req.proxyOptions)
624632
return

0 commit comments

Comments
 (0)