Skip to content

fix: cancel orphaned finish scheduler when a second break starts#1803

Open
vyguera wants to merge 2 commits into
hovancik:trunkfrom
vyguera:fix/cancel-orphaned-break-scheduler
Open

fix: cancel orphaned finish scheduler when a second break starts#1803
vyguera wants to merge 2 commits into
hovancik:trunkfrom
vyguera:fix/cancel-orphaned-break-scheduler

Conversation

@vyguera

@vyguera vyguera commented Jun 17, 2026

Copy link
Copy Markdown

When two breaks start in quick succession via concurrent CLI calls, the breakStarted handler assigns a new Scheduler to this.scheduler without cancelling the existing finishMicrobreak timer. That timer keeps running independently. If the screen locks before it fires, both breaks are force-closed and microbreakWins is set to null. When the orphaned timer fires shortly after, it calls finishMicrobreak against null and throws.

The fix cancels the previous scheduler in both microbreakStarted and breakStarted before creating the new one. A null guard in closeWindows is included as a defensive fallback.

Tests in test/breaksPlanner.js verify that emitting breakStarted while a finishMicrobreak timer is running cancels the orphaned timer, and vice versa.

To reproduce: run stretchly long and stretchly mini within a second of each other, then lock the screen while both overlays are active and keep it locked for at least the Mini break duration. Fixes #1802.

ruben.viguera added 2 commits June 17, 2026 10:11
When two breaks start in quick succession (e.g. via concurrent CLI
calls), the breakStarted handler replaces this.scheduler without
cancelling the previous finishMicrobreak timer. That orphaned timer
fires after the screen locks and both breaks are force-closed, calling
finishMicrobreak/finishBreak against a null windowArray.

Cancel the previous scheduler in both microbreakStarted and breakStarted
before creating the new one. Also add a null guard in closeWindows as a
defensive fallback.

Fixes hovancik#1802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash: TypeError: windowArray is not iterable in closeWindows during finishBreak

1 participant