destroy has an early termination when destroyed is already true. Setting destroyed = true before calling abort() stops Node.js from internally closing the socket, potentially leading to memory leaks.
It also breaks the behavior of abort() since Node.js deprecated it in favor of destroy() (as Node.js internally relies on destroy() logic to terminate the call.
Checklist
[x] I have ensured my pull request is not behind the main or master branch of the original repository.
[x] I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
[x] I have written a commit message that passes commitlint linting.
[x] I have ensured that my code changes pass linting tests.
[x] I have ensured that my code changes pass unit tests.
[x] I have described my pull request and the reasons for code changes along with context if necessary.
The current
this.req.destroyed = true
hack that was added in https://github.com/ladjs/superagent/commit/8b1923d4a0f22bec49ec6eebead499ce0ac7f694 actually breaks the behavior of 14.0.0.Looking at
v14.0.0
's HTTP client's code, theabort
method internally callsdestroy
.destroy
has an early termination whendestroyed
is alreadytrue
. Settingdestroyed = true
before callingabort()
stops Node.js from internally closing the socket, potentially leading to memory leaks.It also breaks the behavior of
abort()
since Node.js deprecated it in favor ofdestroy()
(as Node.js internally relies ondestroy()
logic to terminate the call.Checklist