querysub 0.562.0 → 0.563.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.562.0",
3
+ "version": "0.563.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -642,8 +642,11 @@ const resyncServicesBase = runInSerial(measureWrap(async function resyncServices
642
642
  time: Date.now(),
643
643
  });
644
644
 
645
+ // Every launch goes through the future screen and a rename, releases and plain restarts alike. The new process is up before the old one is touched, so nothing waits on a shutdown, and the pane it runs in is always new - which is what makes it a distinct process with its own log.
646
+ let launchScreenName = getFutureScreenName(screenName);
645
647
  let launchId = await runScreenCommand({
646
- screenName,
648
+ screenName: launchScreenName,
649
+ folder,
647
650
  command: instanceParameters.command,
648
651
  record: {
649
652
  serviceId: config.serviceId,
@@ -655,16 +658,21 @@ const resyncServicesBase = runInSerial(measureWrap(async function resyncServices
655
658
  });
656
659
  await delay(2000);
657
660
  let newScreens = await getScreenState(false);
658
- let foundScreen = newScreens.find(x => x.screenName === screenName);
661
+ let foundScreen = newScreens.find(x => x.screenName === launchScreenName);
659
662
  if (!foundScreen) {
660
- console.error(`Just created screen ${screenName}, but it's not in the list of screens!`);
663
+ console.error(`Just created screen ${launchScreenName}, but it's not in the list of screens!`);
661
664
  }
662
665
  let isRunning = foundScreen && await isScreenRunningProcess(foundScreen.pid);
663
666
  if (!isRunning) {
664
667
  let prefix = getTmuxPrefix();
665
- let logs = await runPromise(`${prefix}tmux capture-pane -t ${screenName} -p`);
666
- throw new Error(`${logs}\n\nService ${magenta(screenName)} is not running after starting. Trying again in ${formatTime(MACHINE_RESYNC_INTERVAL)}, or on next change. Last logs above.`);
668
+ let logs = await runPromise(`${prefix}tmux capture-pane -t ${launchScreenName} -p`);
669
+ throw new Error(`${logs}\n\nService ${magenta(launchScreenName)} is not running after starting. Trying again in ${formatTime(MACHINE_RESYNC_INTERVAL)}, or on next change. Last logs above.`);
670
+ }
671
+ // Up and verified, so the old process can go now
672
+ if (foundScreen) {
673
+ screenStateMap.set(launchScreenName, foundScreen);
667
674
  }
675
+ await takeoverFutureScreen({ canonicalScreenName: screenName, screenNamesUsed, screenStateMap });
668
676
  console.log(green(`Service ${magenta(screenName)} is verified to be running after starting (process ${launchId})`));
669
677
  await syncTimeline(foundScreen?.pid);
670
678
 
@@ -183,9 +183,11 @@ export const runScreenCommand = measureWrap(async function runScreenCommand(conf
183
183
  let prefix = getTmuxPrefix();
184
184
  let screenName = config.screenName;
185
185
 
186
- // A launch is ALWAYS a new session, never a new command in the old one. Reusing the session kept the pane, and the pane's pid and start time are what identify the process - so the "new" process was indistinguishable from the one before it and appended to its log. Every path goes through this, including an immediate zero-overlap deploy: a special case for that would be a second flow to get wrong.
186
+ // A launch is ALWAYS a brand new session. Callers launch into the "-future" name and rename it over the canonical one once the new process is up, so starting a replacement never waits on the old process going away. Nothing is killed here.
187
+ // A leftover session under this name is from a launch that died before its takeover, so it is dead weight rather than something we are replacing.
187
188
  if ((await getScreenState(false)).some(x => x.screenName === screenName)) {
188
- await killScreen({ screenName, skipNodeIdRemoval: true });
189
+ console.log(red(`Removing the leftover session ${screenName} from a launch that never completed`));
190
+ await runPromise(`${prefix}tmux kill-session -t ${screenName}`);
189
191
  }
190
192
  await runPromise(`${prefix}tmux new -s ${screenName} -d`);
191
193