fix: avoid node-fetch@2 gzip "Premature close" crash loop on Node 24 - #53
Open
chrisgrocki wants to merge 1 commit into
Open
fix: avoid node-fetch@2 gzip "Premature close" crash loop on Node 24#53chrisgrocki wants to merge 1 commit into
chrisgrocki wants to merge 1 commit into
Conversation
On Node 18+ (notably Node 24), node-fetch@2's gzip decode throws "Premature close" on Leviton's responses. The error is async and uncaught, becomes an uncaughtException, and Homebridge self-SIGTERMs on it — crash-looping the whole bridge under hb-service. Defaulting compress:false skips the failing gzip path; verified 4/4 200 OK on Node 24 where gzip failed 4/4. Fixes tabrindle#52. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJbj8QvW5GdZbcDAXgqMHV
|
I can confirm this will fix it. I modified the files locally using vi with the changes proposed and it addressed the issue here as well. |
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.
Fixes #52.
Problem
On Node.js 24, every
api.jsrequest fails withFetchError: ... Premature close, thrown fromnode-fetch@2's gzip (Gunzip) stream. The error is asynchronous and uncaught, so it becomes anuncaughtException; Homebridge's CLI self-SIGTERMs on any uncaughtException, so underhb-servicethe entire bridge crash-loops every ~10s — not just the Leviton platform.It's client-side, not a Leviton outage. The same request on Node 24 fails 4/4 with gzip on, and succeeds 4/4 (
200 OK) withcompress: false. See #52 for the full root-cause analysis and reproduction.Change
Wrap
node-fetchonce to defaultcompress: false, so requests skip the failing gzip-decode path. Minimal and low-risk: a single, well-commented line covering all call sites; callers can still override. Responses come back uncompressed (these are small JSON payloads).This is the verified minimal fix. The longer-term direction (noted in #52) is migrating off the deprecated
node-fetch@2to nativefetch(Node 18+), which I'm happy to follow up on separately.Testing
On Node v24.17.0, against the live API with a valid token: before — 4/4
Premature close; after — 4/4200 OK. In a running Homebridge install, the bridge stops crash-looping and the Leviton accessories load.