Skip to content

Commit

Permalink
Limit chunk data size to 4mb
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Feb 1, 2024
1 parent acbd80d commit 0f90535
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/protocol/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CommandInterface, NetworkType, BackendOptions, DosConfig, InitFsEntry, InitFileEntry } from "../emulators";
import { CommandInterfaceEventsImpl } from "../impl/ci-impl";

const maxDataChunkSize = 4 * 1024 * 1024;

export type ClientMessage =
"wc-install" |
"wc-run" |
Expand Down Expand Up @@ -664,6 +666,22 @@ export class CommandInterfaceOverTransportLayer implements CommandInterface {
}

private async sendDataChunk(chunk: DataChunk): Promise<void> {
if (chunk.data === null || chunk.data.byteLength <= maxDataChunkSize) {
return this.sendFullDataChunk(chunk);
} else {
let pos = 0;
while (pos < chunk.data.byteLength) {
await this.sendFullDataChunk({
type: chunk.type,
name: chunk.name,
data: chunk.data.slice(pos, Math.min(chunk.data.byteLength, pos + maxDataChunkSize)),

Check failure on line 677 in src/protocol/protocol.ts

View workflow job for this annotation

GitHub Actions / build (18.x, 3.1.41, version_116_e)

Trailing spaces not allowed
})

Check failure on line 678 in src/protocol/protocol.ts

View workflow job for this annotation

GitHub Actions / build (18.x, 3.1.41, version_116_e)

Missing semicolon
pos += maxDataChunkSize;
}
}
}

private async sendFullDataChunk(chunk: DataChunk): Promise<void> {
const key = this.dataChunkKey(chunk);
if (this.dataChunkPromise[key] !== undefined) {
throw new Error("sendDataChunk should be accepted before sending new one");
Expand Down

0 comments on commit 0f90535

Please sign in to comment.