better shutdown logic to capture waveapp logs from wavesrv shutdown (#931)

This commit is contained in:
Mike Sawka 2024-10-06 13:40:02 -07:00 committed by GitHub
parent 76ccd83c5c
commit 545a914c4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 4 deletions

View File

@ -65,6 +65,7 @@ func doShutdown(reason string) {
watcher.Close()
}
time.Sleep(500 * time.Millisecond)
log.Printf("shutdown complete\n")
os.Exit(0)
})
}

View File

@ -15,7 +15,7 @@ import * as util from "util";
import winston from "winston";
import { initGlobal } from "../frontend/app/store/global";
import * as services from "../frontend/app/store/services";
import { initElectronWshrpc } from "../frontend/app/store/wshrpcutil";
import { initElectronWshrpc, shutdownWshrpc } from "../frontend/app/store/wshrpcutil";
import { WSServerEndpointVarName, WebServerEndpointVarName, getWebServerEndpoint } from "../frontend/util/endpoints";
import { fetch } from "../frontend/util/fetchutil";
import * as keyutil from "../frontend/util/keyutil";
@ -41,6 +41,8 @@ import { configureAutoUpdater, updater } from "./updater";
const electronApp = electron.app;
let WaveVersion = "unknown"; // set by WAVESRV-ESTART
let WaveBuildTime = 0; // set by WAVESRV-ESTART
let forceQuit = false;
let isWaveSrvDead = false;
const WaveAppPathVarName = "WAVETERM_APP_PATH";
const WaveSrvReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID";
@ -167,10 +169,12 @@ function runWaveSrv(): Promise<boolean> {
env: envCopy,
});
proc.on("exit", (e) => {
if (globalIsQuitting || updater?.status == "installing") {
if (updater?.status == "installing") {
return;
}
console.log("wavesrv exited, shutting down");
forceQuit = true;
isWaveSrvDead = true;
electronApp.quit();
});
proc.on("spawn", (e) => {
@ -935,9 +939,30 @@ electronApp.on("window-all-closed", () => {
electronApp.quit();
}
});
electronApp.on("before-quit", () => {
electronApp.on("before-quit", (e) => {
globalIsQuitting = true;
updater?.stop();
waveSrvProc?.kill("SIGINT");
shutdownWshrpc();
if (forceQuit) {
return;
}
e.preventDefault();
const allWindows = electron.BrowserWindow.getAllWindows();
for (const window of allWindows) {
window.hide();
}
if (isWaveSrvDead) {
console.log("wavesrv is dead, quitting immediately");
forceQuit = true;
electronApp.quit();
return;
}
setTimeout(() => {
console.log("waiting for wavesrv to exit...");
forceQuit = true;
electronApp.quit();
}, 3000);
});
process.on("SIGINT", () => {
console.log("Caught SIGINT, shutting down");

View File

@ -44,6 +44,7 @@ class WSControl {
baseHostPort: string;
lastReconnectTime: number = 0;
eoOpts: ElectronOverrideOpts;
noReconnect: boolean = false;
constructor(
baseHostPort: string,
@ -59,8 +60,13 @@ class WSControl {
setInterval(this.sendPing.bind(this), 5000);
}
shutdown() {
this.noReconnect = true;
this.wsConn.close();
}
connectNow(desc: string) {
if (this.open) {
if (this.open || this.noReconnect) {
return;
}
this.lastReconnectTime = Date.now();
@ -82,6 +88,9 @@ class WSControl {
}
reconnect(forceClose?: boolean) {
if (this.noReconnect) {
return;
}
if (this.open) {
if (forceClose) {
this.wsConn.close(); // this will force a reconnect

View File

@ -128,6 +128,10 @@ function initElectronWshrpc(electronClient: WshClient, eoOpts: ElectronOverrideO
addWSReconnectHandler(wpsReconnectHandler);
}
function shutdownWshrpc() {
globalWS?.shutdown();
}
function initWshrpc(windowId: string): WSControl {
DefaultRouter = new WshRouter(new UpstreamWshRpcProxy());
const handleFn = (event: WSEventType) => {
@ -163,5 +167,6 @@ export {
sendRpcCommand,
sendRpcResponse,
sendWSCommand,
shutdownWshrpc,
WindowRpcClient,
};