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

Work around qemu/emulator port conflicts by using net.createConnection instead of net.createServer #724

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

---

## [5.8.4] 2023-10-23
## [5.8.4 - 5.8.5] 2023-10-23

### Added

- Added support for hydration of platform-specific binary deps (namely: Python); fixes #1457


### Fixed

- Fixed issue where qemu/emulator port conflicts were not detected with our open port tester; fixes 1441

---

## [5.8.3] 2023-10-17
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "src/index.js",
"scripts": {
"test": "npm run lint && npm run test:integration && npm run coverage",
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-spec",
"test:integration": "cross-env tape 'test/integration/**/*-test.js' | tap-spec",
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc",
"test:integration": "cross-env tape 'test/integration/**/*-test.js' | tap-arc",
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
"lint": "eslint . --fix",
"rc": "npm version prerelease --preid RC",
Expand Down Expand Up @@ -72,7 +72,7 @@
"nyc": "~15.1.0",
"pkg": "~5.8.1",
"proxyquire": "~2.1.3",
"tap-spec": "~5.0.0",
"tap-arc": "~1.1.0",
"tape": "~5.7.2",
"tiny-json-http": "~7.5.1"
},
Expand Down
38 changes: 23 additions & 15 deletions src/sandbox/ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,29 @@ module.exports = function getPorts (params, callback) {
*/
function checkPort (checking, ports, name, single, callback) {
let tries = 0
let tester = net.createServer()
let done = false
function check () {
if (tries === 50) {
let msg = `Could not find open port after 50 tries, please close some applications and try again`
return callback(Error(msg))
}
tester.listen(checking)
tester.once('error', err => {
if (err.message.includes('EADDRINUSE')) {
if (single) {
return callback(Error(`Port ${checking} (${name}) is already in use, please select another with prefs.arc\nSee https://arc.codes/docs/en/reference/configuration/local-preferences#ports---list for config`))
}
else {
tries++
checking++
return check()
}
let socket = net.createConnection({ port: checking })
socket.setTimeout(0)
socket.on('timeout', terminate)
socket.on('connect', () => {
terminate()
if (single) {
return callback(Error(`Port ${checking} (${name}) is already in use, please select another with prefs.arc\nSee https://arc.codes/docs/en/reference/configuration/local-preferences#ports---list for config`))
}
else {
tries++
checking++
check()
}
})
tester.once('listening', () => {
tester.close(() => {
socket.on('error', err => {
terminate()
if (err.code === 'ECONNREFUSED') {
// Tester close emits multiple events, so only call back once
if (!done) {
done = true
Expand All @@ -102,8 +103,15 @@ function checkPort (checking, ports, name, single, callback) {
ports[name] = checking
callback()
}
})
}
else {
console.error(`Unknown port checking error`)
return callback(err)
}
})
function terminate () {
if (!socket.destroyed) socket.destroy()
}
}
check()
}
Loading