Skip to content

node-fetch 2.x causes "Premature close" errors with Cloudflare-proxied responses #691

Description

@matthias-praxipal

Our Hubspot API requests started to fail loading deals this morning after cloudflare updated one of their PoPs

The SDK depends on node-fetch@^2.6.0 which has known, unfixed bugs handling chunked gzip responses (node-fetch#1767, node-fetch#1576). It seems a change in Cloudflare now causes ERR_STREAM_PREMATURE_CLOSE errors for SDK consumers with no code change on their side.

Environment

  • @hubspot/api-client: 13.5.0
  • Node.js: 24.17.0 (but also affects 18+)
  • Runtime: Kubernetes pod (linux/amd64)
  • Region: Cloudflare TXL (Berlin) PoP

Reproduction

const hubspot = require('@hubspot/api-client');
const client = new hubspot.Client({ accessToken: process.env.HUBSPOT_ACCESS_TOKEN });
// This fails with "Premature close"
client.crm.deals.basicApi.getPage(100, undefined, ['dealname'], undefined, ['companies'])
  .then(r => console.log('OK:', r.results.length))
  .catch(e => console.error('FAILED:', e.type, e.message));


We switched from basicApi.getPage() to client.apiRequest() with defaultHeaders: { 'Accept-Encoding': 'identity' } to bypass the gzip decompression path for now.

Note that defaultHeaders set on the Client constructor do not propagate to the generated API methods (basicApi.*, ownersApi.*, etc.), they only apply to apiRequest() calls.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions