-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): error when attempting to forward to restricted local port
- Loading branch information
Showing
6 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import _getPort from "get-port" | ||
import { omit } from "lodash" | ||
|
||
export async function getPort(options?: _getPort.Options) { | ||
try { | ||
return await _getPort(options) | ||
} catch (error) { | ||
if (error.code === "EACCES") { | ||
// Upstream library doesn't handle errors where a port is free but we're not allowed to listen on it. | ||
// Fall back to using a random port. | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return _getPort(omit(options, "port")) | ||
} else { | ||
throw error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expect } from "chai" | ||
import { getPort } from "../../../../src/util/network" | ||
|
||
describe("getPort", () => { | ||
it("should fall back to random port if not allowed to bind to specified port", async () => { | ||
const port = await getPort({ port: 0 }) | ||
expect(port).to.not.equal(1) | ||
expect(typeof port).to.equal("number") | ||
}) | ||
}) |
@edvald oops, looks like my little change caused this, decided to submit a fix to upstream library sindresorhus/get-port#39. Somewhat interesting given Apple's changes https://news.ycombinator.com/item?id=18302380.