@@ -451,7 +451,7 @@ export class BonjourDiscovery extends EventEmitter {
451451 try {
452452 await this . initializeBrowsing ( serviceType , domain ) ;
453453 } catch ( error ) {
454- this . cleanup ( ) ;
454+ this . stopBrowsing ( ) ;
455455 throw error ;
456456 }
457457 }
@@ -460,11 +460,19 @@ export class BonjourDiscovery extends EventEmitter {
460460 * Stop browsing for services
461461 */
462462 stopBrowsing ( ) : void {
463- if ( this . _browseProcess && ! this . _browseProcess . killed ) {
464- log . info ( 'Stopping Bonjour discovery' ) ;
465- this . _browseProcess . kill ( 'SIGTERM' ) ;
463+ if ( this . _browseProcess ) {
464+ log . debug ( 'Cleaning up BonjourDiscovery resources' ) ;
465+ if ( ! this . _browseProcess . killed ) {
466+ try {
467+ this . _browseProcess . kill ( 'SIGTERM' ) ;
468+ } catch ( err ) {
469+ log . warn ( `Failed to kill browse process: ${ err } ` ) ;
470+ }
471+ }
466472 }
467- this . cleanup ( ) ;
473+ this . _browseProcess = undefined ;
474+ this . _isDiscovering = false ;
475+ this . _discoveredServices . clear ( ) ;
468476 }
469477
470478 /**
@@ -603,7 +611,7 @@ export class BonjourDiscovery extends EventEmitter {
603611 } ) ;
604612 process . on ( 'close' , ( code : number | null ) => {
605613 log . debug ( `dns-sd browse process closed with code: ${ code } ` ) ;
606- this . cleanup ( ) ;
614+ this . stopBrowsing ( ) ;
607615 } ) ;
608616 }
609617
@@ -632,14 +640,4 @@ export class BonjourDiscovery extends EventEmitter {
632640
633641 return devices ;
634642 }
635-
636- /**
637- * Cleanup resources
638- */
639- private cleanup ( ) : void {
640- log . debug ( 'Cleaning up BonjourDiscovery resources' ) ;
641- this . _browseProcess = undefined ;
642- this . _isDiscovering = false ;
643- this . _discoveredServices . clear ( ) ;
644- }
645643}
0 commit comments