Skip to content

[logging] improve logging of port retry #77868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
@@ -203,6 +203,7 @@ export async function startServer(
})

let portRetryCount = 0
const originalPort = port

server.on('error', (err: NodeJS.ErrnoException) => {
if (
@@ -212,7 +213,6 @@ export async function startServer(
err.code === 'EADDRINUSE' &&
portRetryCount < 10
) {
Log.warn(`Port ${port} is in use, trying ${port + 1} instead.`)
port += 1
portRetryCount += 1
server.listen(port, hostname)
@@ -244,6 +244,12 @@ export async function startServer(

port = typeof addr === 'object' ? addr?.port || port : port

if (portRetryCount) {
Log.warn(
`Port ${originalPort} is in use, using available port ${port} instead.`
)
}

const networkHostname =
hostname ?? getNetworkHost(isIPv6(actualHostname) ? 'IPv6' : 'IPv4')

4 changes: 3 additions & 1 deletion test/integration/cli/test/index.test.js
Original file line number Diff line number Diff line change
@@ -675,7 +675,9 @@ describe('CLI Usage', () => {
await killApp(appTwo).catch(console.error)
}

expect(output).toMatch('⚠ Port 3000 is in use, trying 3001 instead.')
expect(output).toMatch(
'⚠ Port 3000 is in use, using available port 3001 instead.'
)
})

test('-p reserved', async () => {