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() watcher.Close()
} }
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
log.Printf("shutdown complete\n")
os.Exit(0) os.Exit(0)
}) })
} }

View File

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

View File

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

View File

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