Skip to content

[fix] "superagent: double callback bug" with maxResponseSize #1830

@AwesomeStickz

Description

@AwesomeStickz

Describe the bug

Node.js version: v22.14.0

OS version: Windows 11

Description:
When I use maxResponseSize and the response is larger than the size I've set, I receive superagent: double callback bug.

This is the case for any image URLs I tried, and also some other links like https://google.com. However there's also some links that does not cause this, for example: https://example.com

Actual behavior

superagent: double callback bug
superagent: double callback bug
Error: Maximum response size reached
    at IncomingMessage.<anonymous> (D:\test\node_modules\superagent\lib\node\index.js:1034:25)
    at IncomingMessage.emit (node:events:529:35)
    at Readable.read (node:internal/streams/readable:582:10)
    at flow (node:internal/streams/readable:1064:34)
    at resume_ (node:internal/streams/readable:1045:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ETOOLARGE',
  response: null
}

Expected behavior

I should only receive the maximumr esponse size reached error

Code to reproduce

const superagent = require('superagent');

superagent
    .get('https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg')
    .maxResponseSize(1)
    .then((res) => console.log(res.body))
    .catch((err) => console.error(err));

Checklist

  • I have searched through GitHub issues for similar issues. (There is "superagent: double callback bug" with timeout #1801 but that's for timeouts, though these may be related)
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions