Skip to content

Commit

Permalink
Find free local port and use it in `odo debug port-forward' (#1328)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
  • Loading branch information
dgolovin committed Dec 21, 2019
1 parent a5f7a4d commit e42b2ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ 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');
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;
Expand Down Expand Up @@ -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<String>((resolve, reject) => {
cp.stdout.on('data', async (data: string) => {
const port = data.trim().match(/(?<localPort>\d+)\:\d+$/);
if (port.groups.localPort) {
await wait(1000);
if (port?.groups?.localPort) {
await waitPort({
host: 'localhost',
port: parseInt(port.groups.localPort)
Expand Down

0 comments on commit e42b2ee

Please sign in to comment.