Skip to content

Commit

Permalink
Fixes MOD-163 (modrinth#2952)
Browse files Browse the repository at this point in the history
* init: correctly type powerstate in crash state

Signed-off-by: Evan Song <theevansong@gmail.com>

* feat: handle oom_killed and exit_code when a server crashes

Signed-off-by: Evan Song <theevansong@gmail.com>

---------

Signed-off-by: Evan Song <theevansong@gmail.com>
  • Loading branch information
ferothefox authored Nov 18, 2024
1 parent 1aa2299 commit a1a920e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
26 changes: 23 additions & 3 deletions apps/frontend/src/pages/servers/manage/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
:is-server-running="isServerRunning"
:stats="stats"
:server-power-state="serverPowerState"
:power-state-details="powerStateDetails"
:console-output="throttledConsoleOutput"
:socket="socket"
:server="server"
Expand Down Expand Up @@ -312,6 +313,8 @@ const ramData = ref<number[]>([]);
const isActioning = ref(false);
const isServerRunning = computed(() => serverPowerState.value === "running");
const serverPowerState = ref<ServerState>("stopped");
const powerStateDetails = ref<{ oom_killed?: boolean; exit_code?: number }>();
const uptimeSeconds = ref(0);
const firstConnect = ref(true);
const copied = ref(false);
Expand Down Expand Up @@ -488,7 +491,14 @@ const handleWebSocketMessage = (data: WSEvent) => {
reauthenticate();
break;
case "power-state":
updatePowerState(data.state);
if (data.state === "crashed") {
updatePowerState(data.state, {
oom_killed: data.oom_killed,
exit_code: data.exit_code,
});
} else {
updatePowerState(data.state);
}
break;
case "installation-result":
handleInstallationResult(data);
Expand Down Expand Up @@ -606,9 +616,19 @@ const updateStats = (currentStats: Stats["current"]) => {
};
};
const updatePowerState = (state: ServerState) => {
console.log("Power state:", state);
const updatePowerState = (
state: ServerState,
details?: { oom_killed?: boolean; exit_code?: number },
) => {
console.log("Power state:", state, details);
serverPowerState.value = state;
if (state === "crashed") {
powerStateDetails.value = details;
} else {
powerStateDetails.value = undefined;
}
if (state === "stopped" || state === "crashed") {
stopUptimeUpdates();
uptimeSeconds.value = 0;
Expand Down
29 changes: 29 additions & 0 deletions apps/frontend/src/pages/servers/manage/[id]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@
</li>
</div>
</div>
<div v-else-if="props.serverPowerState === 'crashed'" class="flex flex-row gap-4">
<IssuesIcon class="hidden h-8 w-8 text-red sm:block" />

<div class="flex flex-col gap-2">
<div class="font-semibold">{{ serverData?.name }} shut down unexpectedly.</div>
<div class="font-normal">
<template v-if="props.powerStateDetails?.oom_killed">
The server stopped because it ran out of memory. There may be a memory leak caused
by a mod or plugin, or you may need to upgrade your Modrinth Server.
</template>
<template v-else-if="props.powerStateDetails?.exit_code !== undefined">
We could not automatically determine the specific cause of the crash, but your
server exited with code
{{ props.powerStateDetails.exit_code }}.
{{
props.powerStateDetails.exit_code === 1
? "There may be a mod or plugin causing the issue, or an issue with your server configuration."
: ""
}}
</template>
<template v-else> We could not determine the specific cause of the crash. </template>
<div class="mt-2">You can try restarting the server.</div>
</div>
</div>
</div>
<div v-else class="flex flex-row gap-4">
<IssuesIcon class="hidden h-8 w-8 text-red sm:block" />

Expand Down Expand Up @@ -169,6 +194,10 @@ type ServerProps = {
stats: Stats;
consoleOutput: string[];
serverPowerState: ServerState;
powerStateDetails?: {
oom_killed?: boolean;
exit_code?: number;
};
isServerRunning: boolean;
server: Server<["general", "mods", "backups", "network", "startup", "ws", "fs"]>;
};
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/types/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export interface WSAuthExpiringEvent {
export interface WSPowerStateEvent {
event: "power-state";
state: ServerState;
// if state "crashed"
oom_killed?: boolean;
exit_code?: number;
}

export interface WSAuthIncorrectEvent {
Expand Down

0 comments on commit a1a920e

Please sign in to comment.