Skip to content

Commit

Permalink
fix: use portfinder instead of get-port
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <[email protected]>
  • Loading branch information
hacdias committed Apr 17, 2020
1 parent d4025d4 commit 5747b82
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
25 changes: 20 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"electron-updater": "^4.2.5",
"fix-path": "^3.0.0",
"fs-extra": "^9.0.0",
"get-port": "^5.1.1",
"go-ipfs-dep": "0.4.23",
"i18next": "^19.4.2",
"i18next-electron-language-detector": "0.0.10",
Expand All @@ -90,6 +89,7 @@
"is-ipfs": "^1.0.0",
"multiaddr": "^7.4.3",
"multiaddr-to-uri": "^5.1.0",
"portfinder": "^1.0.25",

This comment has been minimized.

Copy link
@lidel

lidel Apr 17, 2020

Member

@hacdias why we switched from get-port to portfinder?
(asking because I used it in Companion in Brave)

This comment has been minimized.

Copy link
@hacdias

hacdias Apr 18, 2020

Author Member

So the PR got lost because I misclicked 'rebase' instead of 'squash': #1410. get-port is giving other ports other than our preferred one even it's available: I was being able to reproduce it every time I stopped IPFS and then clicked 'start' (or just 'restart'). It would say the ports were not available and I needed to change them. The bug seems to have been reported (sindresorhus/get-port#43). However, it wasn't fixed.

This comment has been minimized.

Copy link
@hacdias

hacdias Apr 18, 2020

Author Member

portfinder seems to be much more used and has no bug-related issues opened so I tried it and it worked well.

"recursive-readdir": "^2.2.2",
"stream-to-pull-stream": "^1.7.3",
"sudo-prompt": "^9.1.1",
Expand Down
8 changes: 4 additions & 4 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { join } = require('path')
const fs = require('fs-extra')
const multiaddr = require('multiaddr')
const http = require('http')
const getPort = require('get-port')
const portfinder = require('portfinder')
const { shell } = require('electron')
const i18n = require('i18next')
const { showDialog } = require('../dialogs')
Expand Down Expand Up @@ -137,7 +137,7 @@ async function checkPortsArray (ipfsd, addrs) {
continue
}

const freePort = await getPort({ port: getPort.makeRange(port, port + 100) })
const freePort = await portfinder.getPortPromise({ port: port, stopPort: port + 100 })

if (port !== freePort) {
const opt = showDialog({
Expand Down Expand Up @@ -184,8 +184,8 @@ async function checkPorts (ipfsd) {
const apiPort = parseInt(configApiMa.nodeAddress().port, 10)
const gatewayPort = parseInt(configGatewayMa.nodeAddress().port, 10)

const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })
const freeGatewayPort = await portfinder.getPortPromise({ port: gatewayPort, stopPort: gatewayPort + 100 })
const freeApiPort = await portfinder.getPortPromise({ port: apiPort, stopPort: apiPort + 100 })

const busyApiPort = apiPort !== freeApiPort
const busyGatewayPort = gatewayPort !== freeGatewayPort
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/launch.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const delay = require('delay')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const { makeRepository } = require('./utils/ipfsd')
const getPort = require('get-port')
const portfinder = require('portfinder')

const expect = chai.expect
chai.use(dirtyChai)
Expand All @@ -23,6 +23,10 @@ function createTmpDir () {
return tmp.dirSync({ unsafeCleanup: true }).name
}

async function getPort () {
return portfinder.getPortPromise()
}

const timeout = process.env.CI ? 180000 : 60000

describe('Application launch', function () {
Expand Down

0 comments on commit 5747b82

Please sign in to comment.