@@ -141,6 +141,9 @@ export async function launchAndroidHost(adbClient: AdbClient, hostId: string) {
141141 const fridaServerStream = await deviceClient . shell (
142142 runAsRoot ( ANDROID_FRIDA_BINARY_PATH , '-l' , `127.0.0.1:${ FRIDA_ALTERNATE_PORT } ` )
143143 ) ;
144+ fridaServerStream . on ( 'error' , ( e ) => {
145+ console . log ( 'Frida server error:' , e ) ;
146+ } ) ;
144147 fridaServerStream . pipe ( process . stdout ) ;
145148
146149 // Wait until the server becomes accessible
@@ -159,10 +162,18 @@ export async function launchAndroidHost(adbClient: AdbClient, hostId: string) {
159162 const errorMessage = e ?. code === 'wait-loop-failed'
160163 ? 'Frida server did not startup before timeout'
161164 : e . message ?? e ;
162- console . log ( 'Fride launch failed:' , errorMessage ) ;
165+ console . log ( 'Frida launch failed:' , errorMessage ) ;
163166
164167 // Try cleaning up the Frida server (async) just in case it's corrupted somehow:
165- deviceClient . shell ( runAsRoot ( 'rm' , '-f' , ANDROID_FRIDA_BINARY_PATH ) ) . catch ( ( e ) => {
168+ deviceClient . shell ( runAsRoot ( 'rm' , '-f' , ANDROID_FRIDA_BINARY_PATH ) )
169+ . then ( ( stream ) => {
170+ return new Promise < void > ( ( resolve , reject ) => {
171+ stream . on ( 'close' , resolve ) ;
172+ stream . on ( 'error' , reject ) ;
173+ stream . resume ( ) ;
174+ } ) ;
175+ } )
176+ . catch ( ( e ) => {
166177 console . warn (
167178 `Failed to clean up broken Frida server on ${ hostId } at ${ ANDROID_FRIDA_BINARY_PATH } : ${
168179 e . message ?? e
@@ -182,6 +193,14 @@ const getFridaStream = (hostId: string, deviceClient: DeviceClient) =>
182193 throw new CustomError ( `Couldn't connect to Frida for ${ hostId } ` , {
183194 statusCode : 502
184195 } ) ;
196+ } )
197+ . then ( ( stream ) => {
198+ // Handle errors on this stream - the Frida session will expose them properly,
199+ // but we want to make sure nothing hard-crashes in the meantime.
200+ stream . on ( 'error' , ( e ) => {
201+ console . warn ( `Frida stream error for ${ hostId } :` , e ) ;
202+ } ) ;
203+ return stream ;
185204 } ) ;
186205
187206// Frida session cache for Android hosts
0 commit comments