Skip to content

Windows raw kernel launch failure fix #11603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/11574.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix intermittent launch failure with raw kernels on windows.
42 changes: 40 additions & 2 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2929,6 +2929,7 @@
"@koa/cors": "^3.0.0",
"@loadable/component": "^5.12.0",
"@nteract/messaging": "^7.0.0",
"@types/tcp-port-used": "^1.0.0",
"ansi-regex": "^4.1.0",
"arch": "^2.1.0",
"azure-storage": "^2.10.3",
Expand Down Expand Up @@ -2972,6 +2973,7 @@
"strip-ansi": "^5.2.0",
"sudo-prompt": "^8.2.0",
"svg-to-pdfkit": "^0.1.8",
"tcp-port-used": "^1.0.1",
"tmp": "^0.0.29",
"tree-kill": "^1.2.2",
"typescript-char": "^0.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ export enum Telemetry {
RawKernelSessionStartSuccess = 'DS_INTERNAL.RAWKERNEL_SESSION_START_SUCCESS',
RawKernelSessionStartUserCancel = 'DS_INTERNAL.RAWKERNEL_SESSION_START_USER_CANCEL',
RawKernelSessionStartTimeout = 'DS_INTERNAL.RAWKERNEL_SESSION_START_TIMEOUT',
RawKernelSessionStartException = 'DS_INTERNAL.RAWKERNEL_SESSION_START_EXCEPTION'
RawKernelSessionStartException = 'DS_INTERNAL.RAWKERNEL_SESSION_START_EXCEPTION',
RawKernelProcessLaunch = 'DS_INTERNAL.RAWKERNEL_PROCESS_LAUNCH'
}

export enum NativeKeyboardCommandTelemetry {
Expand Down
22 changes: 22 additions & 0 deletions src/client/datascience/kernel-launcher/kernelProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';

import { ChildProcess } from 'child_process';
import * as tcpPortUsed from 'tcp-port-used';
import { Event, EventEmitter } from 'vscode';
import { PYTHON_LANGUAGE } from '../../common/constants';
import { traceError, traceInfo, traceWarning } from '../../common/logger';
Expand All @@ -11,6 +12,8 @@ import { IProcessServiceFactory, ObservableExecutionResult } from '../../common/
import { Resource } from '../../common/types';
import { noop, swallowExceptions } from '../../common/utils/misc';
import { PythonInterpreter } from '../../interpreter/contracts';
import { captureTelemetry } from '../../telemetry';
import { Telemetry } from '../constants';
import { IJupyterKernelSpec } from '../types';
import { findIndexOfConnectionFile } from './kernelFinder';
import { PythonKernelLauncherDaemon } from './kernelLauncherDaemon';
Expand Down Expand Up @@ -61,6 +64,8 @@ export class KernelProcess implements IKernelProcess {
await this.kernelDaemon?.interrupt();
}
}

@captureTelemetry(Telemetry.RawKernelProcessLaunch, undefined, true)
public async launch(): Promise<void> {
if (this.launchedOnce) {
throw new Error('Kernel has already been launched.');
Expand Down Expand Up @@ -103,6 +108,9 @@ export class KernelProcess implements IKernelProcess {
}
}
);

// Don't return until our heartbeat channel is open for connections
return this.waitForHeartbeat();
}

public async dispose(): Promise<void> {
Expand All @@ -119,6 +127,20 @@ export class KernelProcess implements IKernelProcess {
swallowExceptions(() => this.connectionFile?.dispose());
}

// Make sure that the heartbeat channel is open for connections
private async waitForHeartbeat() {
try {
// Wait until the port is open for connection
// First parameter is wait between retries, second parameter is total wait before error
await tcpPortUsed.waitUntilUsed(this.connection.hb_port, 200, 30_000);
} catch (error) {
// Make sure to dispose if we never get a heartbeat
this.dispose().ignoreErrors();
traceError('Timed out waiting to get a heartbeat from kernel process.');
throw new Error('Timed out waiting to get a heartbeat from kernel process.');
}
}

private async createAndUpdateConnectionFile() {
this.connectionFile = await this.file.createTemporaryFile('.json');
await this.file.writeFile(this.connectionFile.filePath, JSON.stringify(this._connection), {
Expand Down
1 change: 1 addition & 0 deletions src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,7 @@ export interface IEventNamePropertyMapping {
// Raw kernel timing events
[Telemetry.RawKernelSessionConnect]: never | undefined;
[Telemetry.RawKernelStartRawSession]: never | undefined;
[Telemetry.RawKernelProcessLaunch]: never | undefined;

// Raw kernel single events
[Telemetry.RawKernelSessionStartSuccess]: never | undefined;
Expand Down