Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix issues around comm and session lifecycles #6278

Merged
merged 2 commits into from
Feb 14, 2025
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
10 changes: 8 additions & 2 deletions extensions/positron-supervisor/src/KallichoreSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,14 @@ export class KallichoreSession implements JupyterLanguageRuntimeSession {
}

removeClient(id: string): void {
const commOpen = new CommCloseCommand(id);
this.sendCommand(commOpen);
// Ignore this if the session is already exited; an exited session has
// no clients
if (this._runtimeState === positron.RuntimeState.Exited) {
this.log(`Ignoring request to close comm ${id}; kernel has already exited`, vscode.LogLevel.Debug);
return;
}
const commClose = new CommCloseCommand(id);
this.sendCommand(commClose);
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/vs/workbench/api/common/positron/extHostLanguageRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as extHostProtocol from './extHost.positron.protocol.js';
import { Emitter } from '../../../../base/common/event.js';
import { DisposableStore, IDisposable } from '../../../../base/common/lifecycle.js';
import { Disposable, LanguageRuntimeMessageType } from '../extHostTypes.js';
import { RuntimeClientType } from './extHostTypes.positron.js';
import { RuntimeClientState, RuntimeClientType, RuntimeExitReason } from './extHostTypes.positron.js';
import { ExtHostRuntimeClientInstance } from './extHostClientInstance.js';
import { ExtensionIdentifier, IExtensionDescription } from '../../../../platform/extensions/common/extensions.js';
import { URI } from '../../../../base/common/uri.js';
Expand Down Expand Up @@ -351,7 +351,19 @@ export class ExtHostLanguageRuntime implements extHostProtocol.ExtHostLanguageRu

// Hook up the session end (exit) handler
session.onDidEndSession(exit => {
// Notify the main thread that the session has ended
this._proxy.$emitLanguageRuntimeExit(handle, exit);

// If the session isn't exiting in order to restart, then we need
// to clean up its resources.
if (exit.reason !== RuntimeExitReason.Restart) {
session.dispose();
}

// Note that we don't remove the session from the list of sessions;
// that would invalidate the handles of all subsequent sessions
// since we store them in an array. The session remains in an inert
// state.
});

// Register the runtime
Expand Down Expand Up @@ -887,6 +899,9 @@ export class ExtHostLanguageRuntime implements extHostProtocol.ExtHostLanguageRu
// Dispose the client instance when the runtime exits
this._runtimeSessions[handle].onDidChangeRuntimeState(state => {
if (state === RuntimeState.Exited) {
// Mark the client instance as already closed so disposal
// doesn't try to close it
clientInstance.setClientState(RuntimeClientState.Closed);
clientInstance.dispose();
}
});
Expand Down