Skip to content

OAuth token refresh reliably fails with "Premature close" on current Electron/Node — root cause is a Node.js v24.17.0 regression (nodejs/node#63989), not this module #99

Description

@daotsc

Ran into this error and was able to bypass it. Hope this helps. Here is what the AI has to say about it:

This isn't an auth/credentials/network problem — I've traced it to a specific upstream regression and confirmed it's environment-driven, not config-driven.

Root cause

  • nodejs/node#63989 — a confirmed regression in Node.js v24.17.0 (changes to http.Agent keep-alive socket reuse) that breaks under load. v24.16.0 and earlier are unaffected.
  • That regression exposes a latent bug in node-fetch@2node-fetch/node-fetch#1767 — whose malformed-chunked-response detector throws false-positive ERR_STREAM_PREMATURE_CLOSE on reused keep-alive sockets.
  • gaxios@6 (the transport behind googleapis/google-auth-library) falls back to node-fetch@2 whenever there's no browser window global — which is always true for a MagicMirror node_helper.js, since it runs inside Electron's main process. So this hits every install running an Electron build that bundles Node ≥24.17.0.
  • Confirmed reproducible standalone via ELECTRON_RUN_AS_NODE=1 electron -e ... with the exact same credentials — i.e. it's the Electron-bundled Node runtime itself, not network/DNS/proxy/IPv6 (all separately ruled out) and not anything specific to my machine.
  • Same failure independently reported hitting Railway deployments, Firebase CLI in Cloud Build, and Deno — so it's a broad ecosystem issue, not particular to this module or to Electron.

Why this is worth flagging here

Since every MagicMirror install runs node_helper.js inside Electron's main process, every user who updates to a current Electron release will hit this the moment Electron bundles Node ≥24.17.0 — with no config change on their end. It'll likely present to users as "calendar just stopped working" with a confusing gaxios stack trace, same as it did for me.

Workaround

Bypassing googleapis/gaxios for the runtime OAuth refresh + Calendar API calls, and using Node's built-in https module directly, avoids the bug entirely (confirmed working). Happy to share the patch/open a PR if useful — it's a fairly small, self-contained change to node_helper.js's token-refresh and events.list calls.

Environment

  • Electron 42.5.2 (bundled Node 24.17.0)
  • googleapis/google-auth-library via gaxios 6.7.1 → node-fetch 2.7.0
  • Raspberry Pi 5, Debian 12, MagicMirror 2.37.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions