Skip to content

Commit 4e9b6a8

Browse files
committed
Release chunk buffer regardless of submit outcome
Move chunk.bytes = null into a finally so a failed submission also releases its 2 MiB. Today the buffer is only freed on success; on failure (stall, retry, abort) it stays alive via the closure, pinning memory for the lifetime of the upload. The payload is re-streamed from disk on the next attempt, so dropping the in-memory copy is always safe.
1 parent 08c2c0d commit 4e9b6a8

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

packages/cli/src/bulletin/store.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -788,26 +788,34 @@ export async function storeChunkedFileToBulletin(
788788
submitChunk: async (chunk) => {
789789
const nonce = waveNonces.get(chunk.index)!;
790790

791-
await storeContentOnBulletin({
792-
rpc: parameters.rpc,
793-
signer: parameters.signer,
794-
contentBytes: chunk.bytes,
795-
contentCid: chunk.cid,
796-
codecValue: CODEC.RAW,
797-
hashCodeValue: HASH.SHA2_256,
798-
nonce,
799-
client: activeClient,
800-
waitForFinalization,
801-
});
802-
803-
manifestState.completedBlocks.set(chunk.index, {
804-
index: chunk.index,
805-
cid: chunk.cid,
806-
length: chunk.length,
807-
});
808-
809-
completedChunks += 1;
810-
parameters.onProgress?.(chunk.index + 1, totalChunks, "stored");
791+
try {
792+
await storeContentOnBulletin({
793+
rpc: parameters.rpc,
794+
signer: parameters.signer,
795+
contentBytes: chunk.bytes,
796+
contentCid: chunk.cid,
797+
codecValue: CODEC.RAW,
798+
hashCodeValue: HASH.SHA2_256,
799+
nonce,
800+
client: activeClient,
801+
waitForFinalization,
802+
});
803+
804+
manifestState.completedBlocks.set(chunk.index, {
805+
index: chunk.index,
806+
cid: chunk.cid,
807+
length: chunk.length,
808+
});
809+
810+
completedChunks += 1;
811+
parameters.onProgress?.(chunk.index + 1, totalChunks, "stored");
812+
} finally {
813+
// Release the chunk's 2 MiB Buffer regardless of outcome. On
814+
// success it is already persisted; on failure it must not pin
815+
// memory while the caller decides whether to retry — the
816+
// payload is re-streamed from disk on the next attempt.
817+
chunk.bytes = null as unknown as Uint8Array;
818+
}
811819
},
812820
});
813821

0 commit comments

Comments
 (0)