Skip to content

Commit e42b2ee

Browse files
authored
Find free local port and use it in `odo debug port-forward' (#1328)
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent a5f7a4d commit e42b2ee

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@
10411041
"binary-search": "^1.3.6",
10421042
"byline": "^5.0.0",
10431043
"fs-extra": "^8.1.0",
1044+
"get-port": "^5.1.0",
10441045
"git-fetch-pack": "^0.1.1",
10451046
"git-transport-protocol": "^0.1.0",
10461047
"globby": "^10.0.1",

src/openshift/component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import { ChildProcess } from 'child_process';
1313
import { CliExitData } from '../cli';
1414
import { isURL } from 'validator';
1515
import { Refs, Ref, Type } from '../util/refs';
16-
import { Delayer, wait } from '../util/async';
16+
import { Delayer } from '../util/async';
1717
import { Platform } from '../util/platform';
1818
import path = require('path');
1919
import globby = require('globby');
2020
import { selectWorkspaceFolder } from '../util/workspace';
2121
import { exec } from 'child_process';
2222
import { ToolsConfig } from '../tools';
2323
const waitPort = require('wait-port');
24+
const getPort = require('get-port');
2425

2526
export class Component extends OpenShiftItem {
2627
public static extensionContext: ExtensionContext;
@@ -595,12 +596,12 @@ export class Component extends OpenShiftItem {
595596
}
596597

597598
static async startOdoAndConnectDebugger(toolLocation: string, component: OpenShiftObject, config: DebugConfiguration) {
598-
const cp = exec(`"${toolLocation}" debug port-forward`, {cwd: component.contextPath.fsPath});
599+
const port = await getPort();
600+
const cp = exec(`"${toolLocation}" debug port-forward --local-port ${port}`, {cwd: component.contextPath.fsPath});
599601
return new Promise<String>((resolve, reject) => {
600602
cp.stdout.on('data', async (data: string) => {
601603
const port = data.trim().match(/(?<localPort>\d+)\:\d+$/);
602-
if (port.groups.localPort) {
603-
await wait(1000);
604+
if (port?.groups?.localPort) {
604605
await waitPort({
605606
host: 'localhost',
606607
port: parseInt(port.groups.localPort)

0 commit comments

Comments
 (0)