diff --git a/extension/src/client.ts b/extension/src/client.ts index bbec5ea64..9df39ea2f 100644 --- a/extension/src/client.ts +++ b/extension/src/client.ts @@ -30,9 +30,7 @@ import { LoggerStream } from './LoggerSteam'; const localize = nls.loadMessageBundle(); export class GradleTasksClient implements vscode.Disposable { - // The connectDeadline is a high number because, even though the Java process has been - // started, the gGRPC server is not yet ready to accept connections. - private connectDeadline = 120; + private connectDeadline = 5; // seconds private grpcClient: GrpcClient | null = null; private _onConnect: vscode.EventEmitter = new vscode.EventEmitter< null diff --git a/extension/src/server.ts b/extension/src/server.ts index 322521797..04ff0c1eb 100644 --- a/extension/src/server.ts +++ b/extension/src/server.ts @@ -4,7 +4,7 @@ import * as nls from 'vscode-nls'; import { logger } from './logger'; import { buildGradleServerTask } from './tasks'; -import { isDebuggingServer } from './util'; +import { isDebuggingServer, waitOnTcp } from './util'; const localize = nls.loadMessageBundle(); @@ -38,11 +38,18 @@ export class GradleTasksServer implements vscode.Disposable { private readonly context: vscode.ExtensionContext ) { context.subscriptions.push( - vscode.tasks.onDidStartTaskProcess((event) => { + vscode.tasks.onDidStartTaskProcess(async (event) => { if (event.execution.task.name === SERVER_TASK_NAME) { if (isProcessRunning(event.processId)) { - logger.debug('Gradle server process started'); - this.fireOnReady(); + logger.debug( + 'Gradle server process started, waiting for server to start' + ); + try { + await waitOnTcp('localhost', this.port!); + this.fireOnReady(); + } catch (e) { + logger.error('Gradle server not started:', e.message); + } } else { logger.error('Gradle server processes not started'); } diff --git a/extension/src/test/testUtil.ts b/extension/src/test/testUtil.ts index dd48e5f56..aee14181c 100644 --- a/extension/src/test/testUtil.ts +++ b/extension/src/test/testUtil.ts @@ -23,7 +23,7 @@ export function createTestRunner(pattern: string) { // Create the mocha test const mocha = new Mocha({ ui: 'bdd', - timeout: 130000, + timeout: 60000, color: true, }); mocha.bail(true); diff --git a/extension/src/util.ts b/extension/src/util.ts index d32d406a7..c1543ea9a 100644 --- a/extension/src/util.ts +++ b/extension/src/util.ts @@ -6,6 +6,7 @@ export const isTest = (): boolean => export const isDebuggingServer = (): boolean => process.env.VSCODE_DEBUG_SERVER?.toLowerCase() === 'true'; +const maximumTimeout = 120000; // 2 minutes const tcpTimeout = 300; function tcpExists(host: string, port: number): Promise { @@ -27,14 +28,21 @@ function tcpExists(host: string, port: number): Promise { }); } -async function tryConnect(host: string, port: number): Promise { +async function tryConnect( + host: string, + port: number, + startTime: number +): Promise { const connected = await tcpExists(host, port); if (connected) { return; } - await tryConnect(host, port); + if (Date.now() - startTime >= maximumTimeout) { + throw new Error('Unable to wait on tcp due to maxmium timeout reached'); + } + await tryConnect(host, port, startTime); } export function waitOnTcp(host: string, port: number): Promise { - return tryConnect(host, port); + return tryConnect(host, port, Date.now()); }