Skip to content
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

Fix shutting down a notebook when no session is running #5560

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ export class NotebookSessionService implements vscode.Disposable {
// Construct a wrapping promise that resolves/rejects after the session maps have been updated.
const shutdownPromise = (async () => {
try {
const session = await this.doShutdownRuntimeSession(notebookUri);
await this.doShutdownRuntimeSession(notebookUri);
this._shuttingDownSessionsByNotebookUri.delete(notebookUri);
this.setNotebookSession(notebookUri, undefined);
log.info(`Session ${session.metadata.sessionId} is shutdown`);
} catch (err) {
this._startingSessionsByNotebookUri.delete(notebookUri);
throw err;
Expand All @@ -239,7 +238,7 @@ export class NotebookSessionService implements vscode.Disposable {
return shutdownPromise;
}

async doShutdownRuntimeSession(notebookUri: vscode.Uri): Promise<positron.LanguageRuntimeSession> {
async doShutdownRuntimeSession(notebookUri: vscode.Uri): Promise<void> {
// Get the notebook's session.
let session = this._notebookSessionsByNotebookUri.get(notebookUri);

Expand All @@ -252,16 +251,16 @@ export class NotebookSessionService implements vscode.Disposable {
session = await startingSessionPromise;
} catch (err) {
log.error(`Waiting for notebook runtime to start before shutting down failed. Reason ${err}`);
throw err;

// If the session failed to start, we don't need to do anything.
return;
}
} else {
seeM marked this conversation as resolved.
Show resolved Hide resolved
// If there's no session and no starting session, we don't need to do anything.
return;
}
}

// Ensure that we have a session.
if (!session) {
throw new Error(`Tried to shutdown runtime for notebook without a running runtime: ${notebookUri.path}`);
seeM marked this conversation as resolved.
Show resolved Hide resolved
}

// Start the shutdown sequence.
try {
log.info(`Shutting down runtime ${session.runtimeMetadata.runtimeName} for notebook ${notebookUri.path}`);
Expand Down Expand Up @@ -291,7 +290,7 @@ export class NotebookSessionService implements vscode.Disposable {
throw err;
}

return session;
log.info(`Session ${session.metadata.sessionId} is shutdown`);
}

/**
Expand Down