Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/lib/bonjour/bonjour-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class BonjourDiscovery extends EventEmitter {
try {
await this.initializeBrowsing(serviceType, domain);
} catch (error) {
this.cleanup();
this.stopBrowsing();
throw error;
}
}
Expand All @@ -460,11 +460,19 @@ export class BonjourDiscovery extends EventEmitter {
* Stop browsing for services
*/
stopBrowsing(): void {
if (this._browseProcess && !this._browseProcess.killed) {
log.info('Stopping Bonjour discovery');
this._browseProcess.kill('SIGTERM');
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.cleanup();
this._browseProcess = undefined;
this._isDiscovering = false;
this._discoveredServices.clear();
}

/**
Expand Down Expand Up @@ -603,7 +611,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();
});
}

Expand Down Expand Up @@ -632,14 +640,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();
}
}
Loading