Skip to content

Commit 27c9b14

Browse files
committed
Fix assorted Frida download & install issues
This resolves a bug where the first download for an uncached version would fail (race for data that wasn't buffered I think) and issues where errors elsewhere (e.g. failed downloads) appeared as unhandled rejections without proper tracking for pending downloads.
1 parent 448225e commit 27c9b14

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/dynamic-dep-store.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as path from 'path';
2-
import * as fs from './util/fs';
32
import * as stream from 'stream';
3+
import { CustomError } from '@httptoolkit/util';
44

55
import { HtkConfig } from './config';
6+
import * as fs from './util/fs';
67

78
/**
89
* This retrieves a stream for a dependency file, either from disk if it's already available
@@ -24,18 +25,30 @@ export async function getDependencyStream<K extends readonly string[]>(options:
2425
const tmpDownloadPath = depPath + `.tmp-${Math.random().toString(36).slice(2)}`;
2526
const downloadStream = await options.fetch(options.key);
2627
const diskStream = fs.createWriteStream(tmpDownloadPath);
28+
const resultStream = new stream.PassThrough();
29+
2730
downloadStream.pipe(diskStream);
31+
downloadStream.pipe(resultStream);
2832

2933
downloadStream.on('error', (e) => {
3034
console.warn(`Failed to download dependency to ${depPath}:`, e);
35+
36+
// Clean up the temp download file:
3137
diskStream.destroy();
3238
fs.deleteFile(tmpDownloadPath).catch(() => {});
39+
40+
// Pass the error on to the client:
41+
resultStream.destroy(
42+
new CustomError(`${options.key.join('-')} dependency fetch failed: ${e.message ?? e}`, {
43+
cause: e
44+
})
45+
);
3346
});
3447

3548
diskStream.on('finish', () => {
3649
fs.moveFile(tmpDownloadPath, depPath)
3750
.catch(console.warn);
3851
});
3952

40-
return downloadStream;
53+
return resultStream;
4154
}

src/interceptors/frida/frida-android-integration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ export async function setupAndroidHost(config: HtkConfig, adbClient: AdbClient,
116116
const deviceArch = ANDROID_ABI_FRIDA_ARCH_MAP[firstKnownAbi];
117117
const serverStream = await getFridaServer(config, 'android', deviceArch);
118118

119-
await deviceClient.push(serverStream, ANDROID_FRIDA_BINARY_PATH, 0o555);
119+
const transfer = await deviceClient.push(serverStream, ANDROID_FRIDA_BINARY_PATH, 0o555);
120+
await new Promise<void>((resolve, reject) => {
121+
transfer.on('end', resolve);
122+
transfer.on('error', reject);
123+
});
120124
}
121125

122126
export async function launchAndroidHost(adbClient: AdbClient, hostId: string) {

0 commit comments

Comments
 (0)