Skip to content
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

fix: remove default lower bound from gateway and api port lookup #1991

Merged
merged 1 commit into from
Mar 1, 2022
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
13 changes: 9 additions & 4 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,18 @@ async function checkPorts (ipfsd) {
const apiPort = parseInt(configApiMa.nodeAddress().port, 10)
const gatewayPort = parseInt(configGatewayMa.nodeAddress().port, 10)

const findFreePort = async (port, from) => {
port = Math.max(port, from, 1024)
const findFreePort = async (port) => {
port = Math.max(port, 1024)
return portfinder.getPortPromise({ port, stopPort: port + 100 })
}

const freeGatewayPort = await findFreePort(gatewayPort, 8080)
const freeApiPort = await findFreePort(apiPort, 5001)
const freeGatewayPort = await findFreePort(gatewayPort)
let freeApiPort = await findFreePort(apiPort)

// ensure the picked ports are different
while (freeApiPort === freeGatewayPort) {
freeApiPort = await findFreePort(freeApiPort + 1)
}

const busyApiPort = apiPort !== freeApiPort
const busyGatewayPort = gatewayPort !== freeGatewayPort
Expand Down