Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/server/main-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func doShutdown(reason string) {
watcher.Close()
}
time.Sleep(500 * time.Millisecond)
log.Printf("shutdown complete\n")
os.Exit(0)
})
}
Expand Down
31 changes: 28 additions & 3 deletions emain/emain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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";
Expand All @@ -39,6 +39,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";
Expand Down Expand Up @@ -165,10 +167,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) => {
Expand Down Expand Up @@ -778,9 +782,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");
Expand Down
11 changes: 10 additions & 1 deletion frontend/app/store/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WSControl {
baseHostPort: string;
lastReconnectTime: number = 0;
eoOpts: ElectronOverrideOpts;
noReconnect: boolean = false;

constructor(
baseHostPort: string,
Expand All @@ -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();
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/store/wshrpcutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -163,5 +167,6 @@ export {
sendRpcCommand,
sendRpcResponse,
sendWSCommand,
shutdownWshrpc,
WindowRpcClient,
};