mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 13:24:48 +00:00
23 lines
1.2 KiB
Diff
23 lines
1.2 KiB
Diff
diff --git a/lib/Utils/messages-media.js b/lib/Utils/messages-media.js
|
|
index 0d32dfb4882dfe029ba8804772d7d89404b08e76..4eb2b214b48ef3af48f707237cd19c05e11632a6 100644
|
|
--- a/lib/Utils/messages-media.js
|
|
+++ b/lib/Utils/messages-media.js
|
|
@@ -353,9 +353,17 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi
|
|
const fileSha256 = sha256Plain.digest();
|
|
const fileEncSha256 = sha256Enc.digest();
|
|
encFileWriteStream.write(mac);
|
|
+ // Create finish promises before calling end() to avoid missing the event
|
|
+ const encFinishPromise = once(encFileWriteStream, 'finish');
|
|
+ const originalFinishPromise = originalFileStream ? once(originalFileStream, 'finish') : Promise.resolve();
|
|
encFileWriteStream.end();
|
|
originalFileStream?.end?.();
|
|
stream.destroy();
|
|
+ // Wait for write streams to fully flush to disk before returning encFilePath.
|
|
+ // Without this await, the caller may open a read stream on the file before
|
|
+ // the OS has created it, causing a race-condition ENOENT crash.
|
|
+ await encFinishPromise;
|
|
+ await originalFinishPromise;
|
|
logger?.debug('encrypted data successfully');
|
|
return {
|
|
mediaKey,
|