Skip to content

Commit b905a31

Browse files
author
slit
committed
fix(npm): release HTTPS response stream in postinstall downloadFile (gh#3595)
On Windows, `npm install -g @gastown/gt` fails during the postinstall ZIP extraction with "The process cannot access the file ... because it is being used by another process." PowerShell's Expand-Archive cannot open the ZIP because Node.js still holds a handle to it. Root cause: downloadFile() pipes the HTTPS response into a write stream and resolves after file.close(), but never destroys the response. The readable stream keeps the file handle alive until GC, and Windows mandatory file locking prevents any other process from opening it in the meantime. Unix uses advisory locking, so macOS/Linux are unaffected. Fix: call response.destroy() immediately before resolving on the success path. The redirect path already cleans up (resume + file.close + recurse) and is unchanged. Closes gh#3595 Refs: hq-j6hur.6
1 parent 29a006d commit b905a31

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

npm-package/scripts/postinstall.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ function downloadFile(url, dest) {
8383

8484
file.on('finish', () => {
8585
file.close((err) => {
86-
if (err) reject(err);
87-
else resolve();
86+
if (err) {
87+
reject(err);
88+
return;
89+
}
90+
// On Windows, the HTTPS response stream still holds a file handle
91+
// lock after the write stream closes. If we don't destroy it here,
92+
// PowerShell's Expand-Archive can't open the ZIP for extraction.
93+
response.destroy();
94+
resolve();
8895
});
8996
});
9097
});

0 commit comments

Comments
 (0)