From c53653c8d2904f69c9a0f597077c05b095a14412 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 15 Mar 2026 23:24:55 +0100 Subject: [PATCH 1/2] fix: Ensure dns-sd is always terminated --- src/lib/bonjour/bonjour-discovery.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/lib/bonjour/bonjour-discovery.ts b/src/lib/bonjour/bonjour-discovery.ts index 3f2d9ae2..6665c413 100644 --- a/src/lib/bonjour/bonjour-discovery.ts +++ b/src/lib/bonjour/bonjour-discovery.ts @@ -451,7 +451,7 @@ export class BonjourDiscovery extends EventEmitter { try { await this.initializeBrowsing(serviceType, domain); } catch (error) { - this.cleanup(); + this.stopBrowsing(); throw error; } } @@ -460,11 +460,17 @@ export class BonjourDiscovery extends EventEmitter { * Stop browsing for services */ stopBrowsing(): void { + log.debug('Cleaning up BonjourDiscovery resources'); if (this._browseProcess && !this._browseProcess.killed) { - log.info('Stopping Bonjour discovery'); - this._browseProcess.kill('SIGTERM'); + try { + this._browseProcess.kill('SIGTERM'); + } catch (err) { + log.warn(`Failed to kill browse process: ${err}`); + } } - this.cleanup(); + this._browseProcess = undefined; + this._isDiscovering = false; + this._discoveredServices.clear(); } /** @@ -603,7 +609,7 @@ export class BonjourDiscovery extends EventEmitter { }); process.on('close', (code: number | null) => { log.debug(`dns-sd browse process closed with code: ${code}`); - this.cleanup(); + this.stopBrowsing(); }); } @@ -632,14 +638,4 @@ export class BonjourDiscovery extends EventEmitter { return devices; } - - /** - * Cleanup resources - */ - private cleanup(): void { - log.debug('Cleaning up BonjourDiscovery resources'); - this._browseProcess = undefined; - this._isDiscovering = false; - this._discoveredServices.clear(); - } } From 4b180fd19a8ab511d539a997dfb330e0f9912650 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Mon, 16 Mar 2026 07:27:20 +0100 Subject: [PATCH 2/2] avoid double log --- src/lib/bonjour/bonjour-discovery.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/bonjour/bonjour-discovery.ts b/src/lib/bonjour/bonjour-discovery.ts index 6665c413..9cd82263 100644 --- a/src/lib/bonjour/bonjour-discovery.ts +++ b/src/lib/bonjour/bonjour-discovery.ts @@ -460,12 +460,14 @@ export class BonjourDiscovery extends EventEmitter { * Stop browsing for services */ stopBrowsing(): void { - log.debug('Cleaning up BonjourDiscovery resources'); - if (this._browseProcess && !this._browseProcess.killed) { - try { - this._browseProcess.kill('SIGTERM'); - } catch (err) { - log.warn(`Failed to kill browse process: ${err}`); + if (this._browseProcess) { + log.debug('Cleaning up BonjourDiscovery resources'); + if (!this._browseProcess.killed) { + try { + this._browseProcess.kill('SIGTERM'); + } catch (err) { + log.warn(`Failed to kill browse process: ${err}`); + } } } this._browseProcess = undefined;