fix: clamp polling interval and stop orphaned pollers
- Clamp intervalMs to safe range (1s to 60s) to prevent tight loops - Stop pollers when window is destroyed or project is missing - Use safeIntervalMs for setInterval call Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
2e56176514
commit
b437dc6f30
@@ -1179,10 +1179,23 @@ export function registerMRReviewHandlers(
|
||||
return { success: false, error: 'Could not identify calling window' };
|
||||
}
|
||||
|
||||
// Clamp interval to safe range (1s to 60s)
|
||||
const safeIntervalMs = Number.isFinite(intervalMs)
|
||||
? Math.min(60_000, Math.max(1_000, intervalMs))
|
||||
: 5_000;
|
||||
|
||||
// Start new polling interval
|
||||
const interval = setInterval(async () => {
|
||||
const pollKey = `${projectId}:${mrIid}`;
|
||||
|
||||
// Stop polling if window is destroyed
|
||||
if (!callingWindow || callingWindow.isDestroyed()) {
|
||||
clearInterval(interval);
|
||||
statusPollingIntervals.delete(pollKey);
|
||||
pollingInProgress.delete(pollKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent concurrent polls
|
||||
if (pollingInProgress.has(pollKey)) {
|
||||
return;
|
||||
@@ -1191,14 +1204,18 @@ export function registerMRReviewHandlers(
|
||||
pollingInProgress.add(pollKey);
|
||||
|
||||
try {
|
||||
// Fetch current project to avoid stale config from closure
|
||||
const currentProject = projectStore.getProject(projectId);
|
||||
if (!currentProject) {
|
||||
debugLog('Project not found during poll - stopping poller', { projectId });
|
||||
clearInterval(interval);
|
||||
statusPollingIntervals.delete(pollKey);
|
||||
pollingInProgress.delete(pollKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// Emit status update to renderer
|
||||
if (callingWindow && !callingWindow.isDestroyed()) {
|
||||
// Fetch current project to avoid stale config from closure
|
||||
const currentProject = projectStore.getProject(projectId);
|
||||
if (!currentProject) {
|
||||
debugLog('Project not found during poll', { projectId });
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await getGitLabConfig(currentProject);
|
||||
if (!config) return;
|
||||
@@ -1229,7 +1246,7 @@ export function registerMRReviewHandlers(
|
||||
} finally {
|
||||
pollingInProgress.delete(pollKey);
|
||||
}
|
||||
}, intervalMs);
|
||||
}, safeIntervalMs);
|
||||
|
||||
statusPollingIntervals.set(pollKey, interval);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user