Skip to content

Commit

Permalink
fix shutdown when no session is running
Browse files Browse the repository at this point in the history
  • Loading branch information
seeM committed Nov 28, 2024
1 parent 9598da7 commit 3680596
Showing 1 changed file with 9 additions and 10 deletions.
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 {
// 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}`);
}

// 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

0 comments on commit 3680596

Please sign in to comment.