Skip to content

Commit 8960698

Browse files
committed
Fix ADB ECONNRESET crash, by using forked adbkit
1 parent 239e49f commit 8960698

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

custom-typings/adbkit.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare module 'adbkit' {
1+
declare module '@httptoolkit/adbkit' {
22
import * as stream from 'stream';
33
import * as events from 'events';
44

@@ -34,9 +34,10 @@ declare module 'adbkit' {
3434
pull(
3535
id: string,
3636
path: string
37-
): Promise<events.EventEmitter & { cancel: () => void }>
37+
): Promise<stream.Readable & { cancel: () => void }>
3838
shell(id: string, cmd: string | string[]): Promise<stream.Readable>;
3939
root(id: string): Promise<true>;
40+
on(type: 'error', handler: (error: Error) => void): void;
4041
}
4142

4243
export function createClient(options?: {

package-lock.json

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"homepage": "https://github.com/httptoolkit/httptoolkit-server",
2727
"bugs": "https://github.com/httptoolkit/httptoolkit-server/issues",
2828
"dependencies": {
29+
"@httptoolkit/adbkit": "^2.11.2-crashfix",
2930
"@httptoolkit/browser-launcher": "^1.7.3",
3031
"@httptoolkit/osx-find-executable": "^2.0.0",
3132
"@oclif/command": "^1.5.4",
@@ -37,7 +38,6 @@
3738
"@types/command-exists": "^1.2.0",
3839
"@types/node-fetch": "^2.5.4",
3940
"@types/tmp": "0.0.33",
40-
"adbkit": "^2.11.1",
4141
"async-mutex": "^0.1.3",
4242
"chrome-remote-interface": "^0.28.0",
4343
"command-exists": "^1.2.8",

src/interceptors/android/adb-commands.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as stream from 'stream';
22
import * as path from 'path';
3-
import * as adb from 'adbkit';
3+
import * as adb from '@httptoolkit/adbkit';
44
import { reportError } from '../../error-tracking';
55
import { delay } from '../../util';
66
import { getCertificateFingerprint, parseCert } from '../../certificates';
@@ -9,7 +9,7 @@ export const ANDROID_TEMP = '/data/local/tmp';
99
export const SYSTEM_CA_PATH = '/system/etc/security/cacerts';
1010

1111
export function createAdbClient() {
12-
return adb.createClient({
12+
const client = adb.createClient({
1313
port: process.env['ANDROID_ADB_SERVER_PORT']
1414
? parseInt(process.env['ANDROID_ADB_SERVER_PORT'], 10)
1515
: 5037,
@@ -18,6 +18,12 @@ export function createAdbClient() {
1818
? path.join(process.env['ANDROID_HOME'], 'platform-tools', 'adb')
1919
: 'adb'
2020
});
21+
22+
// We listen for errors and report them. This only happens if adbkit completely
23+
// fails to handle or listen to a connection error. We'd rather report that than crash.
24+
client.on('error', reportError);
25+
26+
return client;
2127
}
2228

2329
// Batch async calls, so that all calls whilst one call is ongoing return the same result.

0 commit comments

Comments
 (0)