fix(runtime): prevent memory leaks and improve shutdown/stream handling across services

This commit is contained in:
2026-02-19 08:33:41 +00:00
parent ddd0662fb8
commit 9ac297c197
8 changed files with 72 additions and 8 deletions

View File

@@ -534,6 +534,12 @@ export class DcRouter {
// If we have DNS challenge handlers, create SmartAcme and wire to certProvisionFunction
if (challengeHandlers.length > 0) {
// Stop old SmartAcme if it exists (e.g., during updateSmartProxyConfig)
if (this.smartAcme) {
await this.smartAcme.stop().catch(err =>
console.error('[DcRouter] Error stopping old SmartAcme:', err)
);
}
this.smartAcme = new plugins.smartacme.SmartAcme({
accountEmail: acmeConfig?.accountEmail || this.options.tls?.contactEmail || 'admin@example.com',
certManager: new StorageBackedCertManager(this.storageManager),
@@ -944,6 +950,25 @@ export class DcRouter {
await this.cacheDb.stop().catch(err => console.error('Error stopping CacheDb:', err));
}
// Clear backoff cache in cert scheduler
if (this.certProvisionScheduler) {
this.certProvisionScheduler.clear();
}
// Allow GC of stopped services by nulling references
this.smartProxy = undefined;
this.emailServer = undefined;
this.dnsServer = undefined;
this.metricsManager = undefined;
this.cacheCleaner = undefined;
this.cacheDb = undefined;
this.tunnelManager = undefined;
this.radiusServer = undefined;
this.smartAcme = undefined;
this.certProvisionScheduler = undefined;
this.remoteIngressManager = undefined;
this.certificateStatusMap.clear();
console.log('All DcRouter services stopped');
} catch (error) {
console.error('Error during DcRouter shutdown:', error);