diff --git a/package-lock.json b/package-lock.json index 89c0b42bc..3bc3f9873 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1243,6 +1243,11 @@ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, + "get-port": { + "version": "5.1.0", + "resolved": "http://localhost:8080/get-port/-/get-port-5.1.0.tgz", + "integrity": "sha512-bjioH1E9bTQUvgaB6VycVy1QVbTZI41yTnF9qkZz6ixgy/uhCH6D63bKeZ6Code/07JYA61MeI94jSdHss8PNA==" + }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", diff --git a/package.json b/package.json index 2bd580ef4..0e8c783bd 100644 --- a/package.json +++ b/package.json @@ -1041,6 +1041,7 @@ "binary-search": "^1.3.6", "byline": "^5.0.0", "fs-extra": "^8.1.0", + "get-port": "^5.1.0", "git-fetch-pack": "^0.1.1", "git-transport-protocol": "^0.1.0", "globby": "^10.0.1", diff --git a/src/openshift/component.ts b/src/openshift/component.ts index caf1b333e..3d131bc8f 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -13,7 +13,7 @@ import { ChildProcess } from 'child_process'; import { CliExitData } from '../cli'; import { isURL } from 'validator'; import { Refs, Ref, Type } from '../util/refs'; -import { Delayer, wait } from '../util/async'; +import { Delayer } from '../util/async'; import { Platform } from '../util/platform'; import path = require('path'); import globby = require('globby'); @@ -21,6 +21,7 @@ import { selectWorkspaceFolder } from '../util/workspace'; import { exec } from 'child_process'; import { ToolsConfig } from '../tools'; const waitPort = require('wait-port'); +const getPort = require('get-port'); export class Component extends OpenShiftItem { public static extensionContext: ExtensionContext; @@ -595,12 +596,12 @@ export class Component extends OpenShiftItem { } static async startOdoAndConnectDebugger(toolLocation: string, component: OpenShiftObject, config: DebugConfiguration) { - const cp = exec(`"${toolLocation}" debug port-forward`, {cwd: component.contextPath.fsPath}); + const port = await getPort(); + const cp = exec(`"${toolLocation}" debug port-forward --local-port ${port}`, {cwd: component.contextPath.fsPath}); return new Promise((resolve, reject) => { cp.stdout.on('data', async (data: string) => { const port = data.trim().match(/(?\d+)\:\d+$/); - if (port.groups.localPort) { - await wait(1000); + if (port?.groups?.localPort) { await waitPort({ host: 'localhost', port: parseInt(port.groups.localPort)