Skip to content
Merged
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
11 changes: 9 additions & 2 deletions apps/relay/src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createApiClient } from "./api-client";
import type { TunnelHttpResponse, TunnelRequest } from "./types";

type WsSocket = {
send: (data: string) => void;
send: (data: string | ArrayBuffer | Uint8Array<ArrayBuffer>) => void;
readyState: number;
close: (code?: number, reason?: string) => void;
};
Expand Down Expand Up @@ -173,8 +173,15 @@ export class TunnelManager {
pending.resolve(msg as unknown as TunnelHttpResponse);
}
} else if (msg.type === "ws:frame") {
if (typeof msg.data !== "string") return;
const clientWs = tunnel.activeChannels.get(msg.id as string);
if (clientWs?.readyState === 1) clientWs.send(msg.data as string);
if (clientWs?.readyState === 1) {
if (msg.encoding === "base64") {
clientWs.send(Buffer.from(msg.data, "base64"));
} else {
clientWs.send(msg.data);
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} else if (msg.type === "ws:close") {
const clientWs = tunnel.activeChannels.get(msg.id as string);
if (clientWs) {
Expand Down
15 changes: 14 additions & 1 deletion packages/host-service/src/tunnel/tunnel-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,22 @@ export class TunnelClient {
}

const localWs = new WebSocket(wsUrl.toString());
localWs.binaryType = "arraybuffer";

localWs.onmessage = (event) => {
this.send({ type: "ws:frame", id: request.id, data: String(event.data) });
const data = event.data;
if (typeof data === "string") {
this.send({ type: "ws:frame", id: request.id, data });
return;
}
if (data instanceof ArrayBuffer) {
this.send({
type: "ws:frame",
id: request.id,
data: Buffer.from(data).toString("base64"),
encoding: "base64",
});
}
};
Comment on lines 196 to 210
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silent drop of unrecognised data types

If event.data is neither a string nor an ArrayBuffer, the frame is silently discarded with no log entry. With binaryType = "arraybuffer" this case is currently unreachable in practice, but if the runtime or environment ever returns a Buffer/Blob, the PTY output will disappear without a trace. An else log helps diagnose future regressions.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/host-service/src/tunnel/tunnel-client.ts
Line: 196-210

Comment:
**Silent drop of unrecognised data types**

If `event.data` is neither a `string` nor an `ArrayBuffer`, the frame is silently discarded with no log entry. With `binaryType = "arraybuffer"` this case is currently unreachable in practice, but if the runtime or environment ever returns a `Buffer`/`Blob`, the PTY output will disappear without a trace. An `else` log helps diagnose future regressions.

How can I resolve this? If you propose a fix, please make it concise.


localWs.onclose = (event) => {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/tunnel-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface TunnelWsFrame {
type: "ws:frame";
id: string;
data: string;
encoding?: "base64";
}

export interface TunnelWsClose {
Expand Down
Loading