Skip to content

Fix duplicate powerMonitor listeners on resume/unlock#1783

Merged
hovancik merged 6 commits into
trunkfrom
copilot/fix-crash-on-system-resume
May 20, 2026
Merged

Fix duplicate powerMonitor listeners on resume/unlock#1783
hovancik merged 6 commits into
trunkfrom
copilot/fix-crash-on-system-resume

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

  • Fix: Make startPowerMonitoring() idempotent by removing old listeners before registering new ones (resume/unlock issue)
  • Revert accidental changes to package.json and package-lock.json
  • Restore app.quit() in before-quit handler (out of scope for this PR)
  • Update CHANGELOG

closes #1782

…uit handler and make startPowerMonitoring idempotent

Agent-Logs-Url: https://github.com/hovancik/stretchly/sessions/d3a21016-8e62-4301-8e1c-6b099d910c3d

Co-authored-by: hovancik <4745859+hovancik@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash on system resume due to maximum call stack size exceeded Fix recursive crash in before-quit handler and duplicate powerMonitor listeners May 19, 2026
Copilot AI requested a review from hovancik May 19, 2026 17:16
@hovancik
Copy link
Copy Markdown
Owner

@copilot no version changes.

why we had app.quit in a first place?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 19, 2026

@copilot no version changes.

why we had app.quit in a first place?

Package files reverted in b4543ef — those were accidentally modified when I ran npm install during testing.

As for why app.quit() was there: it was likely added defensively, perhaps under the assumption that cleanup code in before-quit should be followed by an explicit quit. However, before-quit fires as part of the quit sequence — Electron only fires it when quitting is already in progress. If event.preventDefault() is not called, the quit continues automatically. Calling app.quit() again inside the handler re-triggers the before-quit event, causing unbounded recursion. The fix is simply to let Electron's quit sequence proceed naturally.

@hovancik
Copy link
Copy Markdown
Owner

@copilot dont quess, search git history

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 19, 2026

@copilot dont quess, search git history

It was introduced in commit 9bc1d25 ("Strict mode enhancements", Nov 8 2024) when the before-quit handler was refactored to add strict mode logic. Before that commit the handler was:

app.on('before-quit', () => {
  appIsQuitting = true
  globalShortcut.unregisterAll()
})

When the if/else for strict mode was added, app.quit() was placed in the else branch — apparently to ensure the quit would continue. But that's unnecessary (the quit proceeds naturally when event.preventDefault() is not called) and causes the infinite recursion.

@hovancik
Copy link
Copy Markdown
Owner

@copilot why did you even touch app.quit code? aren't we fixing resume/unlock issue?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot why did you even touch app.quit code? aren't we fixing resume/unlock issue?

You're right — the app.quit() change was out of scope. Restored it in d49b8bc. The PR now only contains the startPowerMonitoring() fix for the resume/unlock issue.

Copilot AI changed the title Fix recursive crash in before-quit handler and duplicate powerMonitor listeners Fix duplicate powerMonitor listeners on resume/unlock May 20, 2026
@hovancik
Copy link
Copy Markdown
Owner

@copilot update changelog

Agent-Logs-Url: https://github.com/hovancik/stretchly/sessions/35717b1c-36ce-4588-9c12-30d216ec10f2

Co-authored-by: hovancik <4745859+hovancik@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot update changelog

Updated in 30204da.

Comment thread CHANGELOG.md
Copilot AI requested a review from hovancik May 20, 2026 07:35
@hovancik hovancik marked this pull request as ready for review May 20, 2026 07:46
@hovancik hovancik merged commit 16f88fb into trunk May 20, 2026
9 checks passed
@hovancik hovancik deleted the copilot/fix-crash-on-system-resume branch May 20, 2026 08:00
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.

[Bug]: Crash on system resume/lock: Maximum call stack size exceeded in BrowserWindow.emit

2 participants