forwardemail / forwardemail/superagent

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

Open
#1,830 0 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

## 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. (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

```js
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

- [x] I have searched through GitHub issues for similar issues. (There is https://github.com/ladjs/superagent/issues/1801 but that's for timeouts, though these _may_ be related)
- [x] I have completely read through the README and documentation.
- [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.