Skip to content

Commit 3a2c363

Browse files
Copilotalexr00
andcommitted
Improve polling lifecycle management to prevent resource leaks
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 24ed0c1 commit 3a2c363

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/notifications/notificationsManager.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
7272
}
7373
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${NOTIFICATIONS_REFRESH_INTERVAL}`)) {
7474
if (this.isPRNotificationsOn()) {
75-
// Restart polling with new interval
76-
this._stopPolling();
75+
// Restart polling with new interval (stopPolling is called inside startPolling)
7776
this._startPolling();
7877
}
7978
}
@@ -443,21 +442,24 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
443442
}
444443

445444
private _stopPolling() {
445+
if (this._pollingDisposable) {
446+
this._pollingDisposable.dispose();
447+
this._pollingDisposable = null;
448+
}
446449
if (this._pollingHandler) {
447450
Logger.appendLine('Notifications: Clearing interval', NotificationsManager.ID);
448451
clearInterval(this._pollingHandler);
449452
this._pollingHandler = null;
450453
}
451-
if (this._pollingDisposable) {
452-
this._pollingDisposable.dispose();
453-
this._pollingDisposable = null;
454-
}
455454
}
456455

457456
private _startPolling() {
458457
if (!this.isPRNotificationsOn()) {
459458
return;
460459
}
460+
// Stop any existing polling to prevent resource leaks
461+
this._stopPolling();
462+
461463
const refreshInterval = this._getRefreshInterval();
462464
Logger.appendLine(`Notifications: Starting polling with interval ${refreshInterval} seconds`, NotificationsManager.ID);
463465
this._pollForNewNotifications();

0 commit comments

Comments
 (0)