Skip to content

Commit

Permalink
fix: ensure using next free port for dev console (#4984)
Browse files Browse the repository at this point in the history
* fix: ensure using next free port for dev console

* chore: add todo comment

---------

Co-authored-by: Shumail Mohyuddin <shumailmohyuddin@gmail.com>
  • Loading branch information
vvagaytsev and shumailxyz committed Aug 30, 2023
1 parent 302768d commit 738828e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"fast-copy": "^3.0.1",
"fs-extra": "^11.1.0",
"get-port": "^5.1.1",
"get-port-please": "^3.0.1",
"glob": "^10.2.6",
"global-agent": "^3.0.0",
"got": "^11.8.6",
Expand Down
9 changes: 7 additions & 2 deletions core/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Router = require("koa-router")
import type PTY from "node-pty-prebuilt-multiarch"
import websockify from "koa-websocket"
import bodyParser = require("koa-bodyparser")
import getPort = require("get-port")
// TODO: switch from get-port-please to get-port once get-port is upgraded to v6.0+ which is ESM only
const { getPort } = require("get-port-please")
import { isArray, omit } from "lodash"

import { BaseServerRequest, resolveRequest, serverRequestSchema, shellCommandParamsSchema } from "./commands"
Expand Down Expand Up @@ -195,7 +196,11 @@ export class GardenServer extends EventEmitter {
} else {
do {
try {
this.port = await getPort({ port: defaultWatchServerPort })
this.port = await getPort({
port: defaultWatchServerPort,
portRange: [defaultWatchServerPort + 1, defaultWatchServerPort + 50],
alternativePortRange: [defaultWatchServerPort - 1, defaultWatchServerPort - 50],
})
await _start()
} catch {}
} while (!this.server)
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock

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

0 comments on commit 738828e

Please sign in to comment.