Remove all manual uses of v8 serialization (#5548)

* Remove all manual uses of v8 serialization

- Seems that sometimes the is a versioning mismatch within the binary
  format causes cluster screen the go grey

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* handle ping

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-06-06 07:34:03 -04:00
1 parent 327978dbc8
commit fae6bff6fb
8 files changed
+58 -50

No files matched your search

+3 -4
View File
@@ -4,7 +4,6 @@
*/
import fs from "fs";
import v8 from "v8";
import * as yaml from "js-yaml";
import type { HelmRepo } from "./helm-repo-manager";
import logger from "../logger";
@@ -15,7 +14,7 @@ import type { SetRequired } from "type-fest";
import { assert } from "console";
interface ChartCacheEntry {
data: Buffer;
data: string; // serialized JSON
mtimeMs: number;
}
@@ -88,7 +87,7 @@ export class HelmChartManager {
HelmChartManager.#cache,
this.repo.name,
{
data: v8.serialize(normalized),
data: JSON.stringify(normalized),
mtimeMs: cacheFileStats.mtimeMs,
},
);
@@ -107,7 +106,7 @@ export class HelmChartManager {
}
}
return v8.deserialize(cacheEntry.data);
return JSON.parse(cacheEntry.data);
}
}
@@ -13,8 +13,8 @@ import { get, once } from "lodash";
import { Node, NodeApi } from "../../../common/k8s-api/endpoints";
import { KubeJsonApi } from "../../../common/k8s-api/kube-json-api";
import logger from "../../logger";
import { TerminalChannels } from "../../../renderer/api/terminal-api";
import type { Kubectl } from "../../kubectl/kubectl";
import { TerminalChannels } from "../../../common/terminal/channels";
export class NodeShellSession extends ShellSession {
ShellType = "node-shell";
+11 -8
View File
@@ -16,11 +16,9 @@ import { UserStore } from "../../common/user-store";
import * as pty from "node-pty";
import { appEventBus } from "../../common/app-event-bus/event-bus";
import logger from "../logger";
import type { TerminalMessage } from "../../renderer/api/terminal-api";
import { TerminalChannels } from "../../renderer/api/terminal-api";
import { deserialize, serialize } from "v8";
import { stat } from "fs/promises";
import { getOrInsertWith } from "../../common/utils";
import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels";
export class ShellOpenError extends Error {
constructor(message: string, options?: ErrorOptions) {
@@ -161,7 +159,7 @@ export abstract class ShellSession {
}
protected send(message: TerminalMessage): void {
this.websocket.send(serialize(message));
this.websocket.send(JSON.stringify(message));
}
protected async getCwd(env: Record<string, string | undefined>): Promise<string> {
@@ -232,17 +230,19 @@ export abstract class ShellSession {
});
this.websocket
.on("message", (data: string | Uint8Array): void => {
.on("message", (rawData: unknown): void => {
if (!this.running) {
return void logger.debug(`[SHELL-SESSION]: received message from ${this.terminalId}, but shellProcess isn't running`);
}
if (typeof data === "string") {
return void logger.silly(`[SHELL-SESSION]: Received message from ${this.terminalId}`, { data });
if (!(rawData instanceof Buffer)) {
return void logger.error(`[SHELL-SESSION]: Received message non-buffer message.`, { rawData });
}
const data = rawData.toString();
try {
const message: TerminalMessage = deserialize(data);
const message: TerminalMessage = JSON.parse(data);
switch (message.type) {
case TerminalChannels.STDIN:
@@ -251,6 +251,9 @@ export abstract class ShellSession {
case TerminalChannels.RESIZE:
shellProcess.resize(message.data.width, message.data.height);
break;
case TerminalChannels.PING:
logger.silly(`[SHELL-SESSION]: ${this.terminalId} ping!`);
break;
default:
logger.warn(`[SHELL-SESSION]: unknown or unhandleable message type for ${this.terminalId}`, message);
break;