Fix: bypass gaxios/fetch for OAuth calls to work around Electron "Premature close" failure - #100
Conversation
…mature close" failure gaxios (google-auth-library's transport) only uses native fetch when a browser `window` global exists; without one - i.e. node_helper.js running inside Electron's main process - it falls back to node-fetch, which reliably fails the OAuth token refresh with "Invalid response body ... Premature close". Root cause is nodejs/node#63989, not this module. Replaces the googleapis-backed OAuth token exchange/refresh and calendar fetch with raw https requests, which are unaffected. Fixes randomBrainstormer#99
|
Thanks for digging into this, your detective work was spot on. You correctly found that the real problem is a bug in Node.js 24.17.0 itself (nodejs/node#63989), not in this module. Great catch. I'd like to fix it in a smaller way than this PR, though. Two concerns:
The good news is your findings point to a much smaller fix. The Google library ships with an option ( Since you can reproduce this reliably (Pi 5 / Electron 42.5.2 / Node 24.17.0), would you mind trying #101 and confirming the "Premature close" error is gone? Your test is the one that really counts here. Thanks again — this was easy to fix because your report was so good. |
Summary
gaxios(google-auth-library's transport) only uses nativefetchwhen a browserwindowglobal exists. With nowindow— i.e.node_helper.jsrunning inside Electron's main process — it falls back to thenode-fetchnpm package, which reliably fails the OAuth token refresh call withInvalid response body ... Premature close(100% reproducible; identical requests succeed instantly via plain Node outside Electron).googleapis-backed OAuth token exchange/refresh and calendar fetch with rawhttpsrequests, which are unaffected by the bug.Fixes #99
Test plan
authenticate/authenticateWeb) still completes whentoken.jsonis missing