From 0d89978333a7f139c53f35f1bb622d08eb73affa Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sun, 11 Oct 2026 01:12:48 +0800 Subject: [PATCH] fix(android): release snapshot streams before closing file handles Retain both non-auto-closing copy streams and destroy them after verification, before awaiting their FileHandle closure. This releases stream-held descriptor references on success and failure instead of deadlocking Android snapshot cleanup. Validation: all 33 JADX subprocess integration tests passed on macOS with Node 24.18.0; check:fast and formatting passed. No real JADX provider execution or Linux/Windows verification was performed locally. --- src/android/AndroidTargetSnapshot.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/android/AndroidTargetSnapshot.ts b/src/android/AndroidTargetSnapshot.ts index 7078caa09..1b372a6dc 100644 --- a/src/android/AndroidTargetSnapshot.ts +++ b/src/android/AndroidTargetSnapshot.ts @@ -1,5 +1,5 @@ import { createHash } from "node:crypto"; -import type { Stats } from "node:fs"; +import type { ReadStream, Stats, WriteStream } from "node:fs"; import { chmod, open, rm, stat, type FileHandle } from "node:fs/promises"; import { join } from "node:path"; import { Transform, type TransformCallback } from "node:stream"; @@ -68,6 +68,8 @@ const copyAndroidSnapshot = async ( ): Promise => { const source = await openRegularFile(sourcePath, { symlinks: "follow" }); let destination: FileHandle | undefined; + let inputStream: ReadStream | undefined; + let outputStream: WriteStream | undefined; let copiedBytes = 0; const hash = createHash("sha256"); try { @@ -93,15 +95,13 @@ const copyAndroidSnapshot = async ( }); try { destination = await open(snapshotPath, "wx", 0o600); - await pipeline( - source.createReadStream({ - start: 0, - end: initial.size, - autoClose: false, - }), - digest, - destination.createWriteStream({ autoClose: false }), - ); + inputStream = source.createReadStream({ + start: 0, + end: initial.size, + autoClose: false, + }); + outputStream = destination.createWriteStream({ autoClose: false }); + await pipeline(inputStream, digest, outputStream); await verifySourceState(source, sourcePath, initial, copiedBytes); const observedSha256 = hash.digest("hex"); if (observedSha256 !== expectedSha256) @@ -115,6 +115,11 @@ const copyAndroidSnapshot = async ( throw cause; } } finally { + // Non-auto-closing streams retain a reference to their FileHandle even + // after pipeline completion. Release those references before awaiting + // descriptor closure, after the admitted source state has been verified. + inputStream?.destroy(); + outputStream?.destroy(); await Promise.all([source.close(), destination?.close()]); } };