Fix: use Node's built-in fetch to avoid Electron/Node 24.17.0 'Premature close' (#99) - #101
Open
randomBrainstormer wants to merge 1 commit into
Open
Fix: use Node's built-in fetch to avoid Electron/Node 24.17.0 'Premature close' (#99)#101randomBrainstormer wants to merge 1 commit into
randomBrainstormer wants to merge 1 commit into
Conversation
…ure close' gaxios (google-auth-library's transport) falls back to node-fetch@2 when there is no browser `window` global — i.e. node_helper.js running inside MagicMirror's Electron main process. On Node 24.17.0 that path throws a false-positive ERR_STREAM_PREMATURE_CLOSE from an http.Agent keep-alive regression (nodejs/node#63989), breaking OAuth token refresh and calendar fetches. Point gaxios at Node's built-in fetch (undici) via its documented fetchImplementation option. undici has its own connection pool and never touches http.Agent, so it sidesteps the bug while keeping the googleapis stack intact and requiring no re-authentication. Both the token refresh and the events.list call go through the OAuth2 client's transporter, so setting it there covers both. Fixes #99
This was referenced Jul 20, 2026
Open
|
Updating my GoogleCalendar module to this branch has resolved the Premature Close error for me and allowed the calendar to be displayed again. |
|
@randomBrainstormer - can you merge your new changes to the main branch? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
Premature closefailure reported in #99, which breaks OAuth token refresh and calendar fetches on current Electron builds.The root cause (thoroughly diagnosed by @daotsc in #99) is an upstream Node.js 24.17.0 regression (nodejs/node#63989), already fixed in a later 24.x.
gaxios(google-auth-library's HTTP transport) falls back to thenode-fetch@2package when there's no browserwindowglobal — i.e.node_helper.jsrunning inside MagicMirror's Electron main process — and that combination trips a false-positiveERR_STREAM_PREMATURE_CLOSEon Node 24.17.0's keep-alive path.Fix
Point
gaxiosat Node's built-infetch(undici) via its documentedfetchImplementationoption. undici has its own connection pool and never toucheshttp.Agent, so it sidesteps the regression. Both the token refresh and theevents.listcall go through the OAuth2 client's transporter, so a single injection point covers both.Why this approach (vs #100)
#100 fixes the same issue by replacing
googleapiswith hand-rolledhttpscalls. This PR is a smaller alternative that:googleapisstack (auto token-refresh persistence, error typing, future API compatibility) instead of reimplementing it;token.jsonformat, so existing users keep working after updating;Testing
npm test— 30/30 passingnpx eslint node_helper.js— cleanevents.listdispatch.