From 7217567ad3eb61bf5e7ecb5df629bedcc5681e70 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 5 Sep 2022 15:29:24 +0200 Subject: [PATCH] Errors in server-main.js. Fixes #160015 --- src/server-main.js | 44 ++++++------------- .../server/node/serverEnvironmentService.ts | 5 ++- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/server-main.js b/src/server-main.js index eabbe0e9e1eb7..4e806323689d0 100644 --- a/src/server-main.js +++ b/src/server-main.js @@ -21,7 +21,7 @@ async function start() { // Do a quick parse to determine if a server or the cli needs to be started const parsedArgs = minimist(process.argv.slice(2), { boolean: ['start-server', 'list-extensions', 'print-ip-address', 'help', 'version', 'accept-server-license-terms'], - string: ['install-extension', 'install-builtin-extension', 'uninstall-extension', 'locate-extension', 'socket-path', 'host', 'port', 'pick-port', 'compatibility'], + string: ['install-extension', 'install-builtin-extension', 'uninstall-extension', 'locate-extension', 'socket-path', 'host', 'port', 'compatibility'], alias: { help: 'h', version: 'v' } }); ['host', 'port', 'accept-server-license-terms'].forEach(e => { @@ -55,13 +55,17 @@ async function start() { * @typedef { import('./vs/server/node/remoteExtensionHostAgentServer').IServerAPI } IServerAPI */ /** @type {IServerAPI | null} */ - const _remoteExtensionHostAgentServer = null; + let _remoteExtensionHostAgentServer = null; /** @type {Promise | null} */ let _remoteExtensionHostAgentServerPromise = null; /** @returns {Promise} */ const getRemoteExtensionHostAgentServer = () => { if (!_remoteExtensionHostAgentServerPromise) { - _remoteExtensionHostAgentServerPromise = loadCode().then((mod) => mod.createServer(address)); + _remoteExtensionHostAgentServerPromise = loadCode().then(async (mod) => { + const server = await mod.createServer(address); + _remoteExtensionHostAgentServer = server; + return server; + }); } return _remoteExtensionHostAgentServerPromise; }; @@ -119,7 +123,7 @@ async function start() { const nodeListenOptions = ( parsedArgs['socket-path'] ? { path: sanitizeStringArg(parsedArgs['socket-path']) } - : { host, port: await parsePort(host, sanitizeStringArg(parsedArgs['port']), sanitizeStringArg(parsedArgs['pick-port'])) } + : { host, port: await parsePort(host, sanitizeStringArg(parsedArgs['port'])) } ); server.listen(nodeListenOptions, async () => { let output = Array.isArray(product.serverGreeting) && product.serverGreeting.length ? `\n\n${product.serverGreeting.join('\n')}\n\n` : ``; @@ -127,7 +131,7 @@ async function start() { if (typeof nodeListenOptions.port === 'number' && parsedArgs['print-ip-address']) { const ifaces = os.networkInterfaces(); Object.keys(ifaces).forEach(function (ifname) { - ifaces[ifname].forEach(function (iface) { + ifaces[ifname]?.forEach(function (iface) { if (!iface.internal && iface.family === 'IPv4') { output += `IP Address: ${iface.address}\n`; } @@ -171,28 +175,25 @@ function sanitizeStringArg(val) { } /** - * If `--pick-port` and `--port` is specified, connect to that port. + * If `--port` is specified and describes a single port, connect to that port. * - * If not and a port range is specified through `--pick-port` + * If `--port`describes a port range * then find a free port in that range. Throw error if no * free port available in range. * - * If only `--port` is provided then connect to that port. - * * In absence of specified ports, connect to port 8000. * @param {string | undefined} host * @param {string | undefined} strPort - * @param {string | undefined} strPickPort * @returns {Promise} * @throws */ -async function parsePort(host, strPort, strPickPort) { +async function parsePort(host, strPort) { let specificPort; if (strPort) { let range; if (strPort.match(/^\d+$/)) { specificPort = parseInt(strPort, 10); - if (specificPort === 0 || !strPickPort) { + if (specificPort === 0) { return specificPort; } } else if (range = parseRange(strPort)) { @@ -208,25 +209,6 @@ async function parsePort(host, strPort, strPickPort) { process.exit(1); } } - // pick-port is deprecated and will be removed soon - if (strPickPort) { - const range = parseRange(strPickPort); - if (range) { - if (range.start <= specificPort && specificPort <= range.end) { - return specificPort; - } else { - const port = await findFreePort(host, range.start, range.end); - if (port !== undefined) { - return port; - } - console.log(`--pick-port: Could not find free port in range: ${range.start} - ${range.end}.`); - process.exit(1); - } - } else { - console.log(`--pick-port "${strPickPort}" is not a valid range. Ranges must be in the form 'from-to' with 'from' an integer larger than 0 and not larger than 'end'.`); - process.exit(1); - } - } return 8000; } diff --git a/src/vs/server/node/serverEnvironmentService.ts b/src/vs/server/node/serverEnvironmentService.ts index c075cf134fdf7..8c5a3c89cb81c 100644 --- a/src/vs/server/node/serverEnvironmentService.ts +++ b/src/vs/server/node/serverEnvironmentService.ts @@ -16,7 +16,6 @@ export const serverOptions: OptionDescriptions = { 'host': { type: 'string', cat: 'o', args: 'ip-address', description: nls.localize('host', "The host name or IP address the server should listen to. If not set, defaults to 'localhost'.") }, 'port': { type: 'string', cat: 'o', args: 'port | port range', description: nls.localize('port', "The port the server should listen to. If 0 is passed a random free port is picked. If a range in the format num-num is passed, a free port from the range (end inclusive) is selected.") }, - 'pick-port': { type: 'string', deprecationMessage: 'Use the range notation in \'port\' instead.' }, 'socket-path': { type: 'string', cat: 'o', args: 'path', description: nls.localize('socket-path', "The path to a socket file for the server to listen to.") }, 'connection-token': { type: 'string', cat: 'o', args: 'token', deprecates: ['connectionToken'], description: nls.localize('connection-token', "A secret that must be included with all requests.") }, 'connection-token-file': { type: 'string', cat: 'o', args: 'path', deprecates: ['connection-secret', 'connectionTokenFile'], description: nls.localize('connection-token-file', "Path to a file that contains the connection token.") }, @@ -93,8 +92,10 @@ export interface ServerParsedArgs { /* ----- server setup ----- */ host?: string; + /** + * A port or a port range + */ port?: string; - 'pick-port'?: string; 'socket-path'?: string; /**