diff --git a/packages/backend/src/managers/applicationManager.ts b/packages/backend/src/managers/applicationManager.ts index b16b66eca..7ff7fd172 100644 --- a/packages/backend/src/managers/applicationManager.ts +++ b/packages/backend/src/managers/applicationManager.ts @@ -329,7 +329,6 @@ export class ApplicationManager extends Publisher { } const portmappings: PodCreatePortOptions[] = []; - // N.B: it may not work with ranges // we expose all ports so we can check the model service if it is actually running for (const image of images) { for (const exposed of image.ports) { diff --git a/packages/backend/src/utils/ports.ts b/packages/backend/src/utils/ports.ts index 11ddaf74e..98e5e0d25 100644 --- a/packages/backend/src/utils/ports.ts +++ b/packages/backend/src/utils/ports.ts @@ -36,25 +36,6 @@ export async function getFreePort(port = 0): Promise { return port; } -/** - * Find a free port range - */ -export async function getFreePortRange(rangeSize: number): Promise { - let port = 9000; - let startPort = port; - - do { - if (await isFreePort(port)) { - ++port; - } else { - ++port; - startPort = port; - } - } while (port + 1 - startPort <= rangeSize); - - return `${startPort}-${port - 1}`; -} - function isFreeAddressPort(address: string, port: number): Promise { const server = net.createServer(); return new Promise((resolve, reject) => @@ -70,37 +51,11 @@ export async function isFreePort(port: number): Promise { } export async function getPortsInfo(portDescriptor: string): Promise { - // check if portDescriptor is a range of ports - if (portDescriptor.includes('-')) { - return await getPortRange(portDescriptor); - } else { - const localPort = await getPort(portDescriptor); - if (!localPort) { - return undefined; - } - return `${localPort}`; - } -} - -/** - * return a range of the same length as portDescriptor containing free ports - * undefined if the portDescriptor range is not valid - * e.g 5000:5001 -> 9000:9001 - */ -async function getPortRange(portDescriptor: string): Promise { - const rangeValues = getStartEndRange(portDescriptor); - if (!rangeValues) { - return Promise.resolve(undefined); - } - - const rangeSize = rangeValues.endRange + 1 - rangeValues.startRange; - try { - // if free port range fails, return undefined - return await getFreePortRange(rangeSize); - } catch (e) { - console.error(e); + const localPort = await getPort(portDescriptor); + if (!localPort) { return undefined; } + return `${localPort}`; } async function getPort(portDescriptor: string): Promise { @@ -122,24 +77,3 @@ async function getPort(portDescriptor: string): Promise { return undefined; } } - -function getStartEndRange(range: string) { - if (range.endsWith('/tcp') || range.endsWith('/udp')) { - range = range.substring(0, range.length - 4); - } - - const rangeValues = range.split('-'); - if (rangeValues.length !== 2) { - return undefined; - } - const startRange = parseInt(rangeValues[0]); - const endRange = parseInt(rangeValues[1]); - - if (isNaN(startRange) || isNaN(endRange)) { - return undefined; - } - return { - startRange, - endRange, - }; -}