Browse Source

Backport PR #10843: Shutdown sessions/terminals on shutdown (#10855)

Co-authored-by: martinRenou <martin.renou@gmail.com>
MeeseeksMachine 3 years ago
parent
commit
c432b13a42
1 changed files with 14 additions and 1 deletions
  1. 14 1
      packages/mainmenu-extension/src/index.ts

+ 14 - 1
packages/mainmenu-extension/src/index.ts

@@ -385,10 +385,23 @@ export function createFileMenu(
           Dialog.cancelButton(),
           Dialog.warnButton({ label: trans.__('Shut Down') })
         ]
-      }).then(result => {
+      }).then(async result => {
         if (result.button.accept) {
           const setting = ServerConnection.makeSettings();
           const apiURL = URLExt.join(setting.baseUrl, 'api/shutdown');
+
+          // Shutdown all kernel and terminal sessions before shutting down the server
+          // If this fails, we continue execution so we can post an api/shutdown request
+          try {
+            await Promise.all([
+              app.serviceManager.sessions.shutdownAll(),
+              app.serviceManager.terminals.shutdownAll()
+            ]);
+          } catch (e) {
+            // Do nothing
+            console.log(`Failed to shutdown sessions and terminals: ${e}`);
+          }
+
           return ServerConnection.makeRequest(
             apiURL,
             { method: 'POST' },