Skip to content

fix: close redirect listiner chanin correctly to no longer stack#10800

Merged
jasonsaayman merged 2 commits intov1.xfrom
fix/maxlistenersexceededwarning-occurs-when-single-request-follows-11-redirects
Apr 24, 2026
Merged

fix: close redirect listiner chanin correctly to no longer stack#10800
jasonsaayman merged 2 commits intov1.xfrom
fix/maxlistenersexceededwarning-occurs-when-single-request-follows-11-redirects

Conversation

@jasonsaayman
Copy link
Copy Markdown
Member

@jasonsaayman jasonsaayman commented Apr 24, 2026

Summary by cubic

Fixes listener stacking in the Node HTTP adapter by cleaning up all redirect-bound sockets with a single close listener. A single request can now follow many redirects without MaxListenersExceededWarning or stale keep‑alive socket refs.

Description

  • Summary of changes
    • Track every socket bound to the outer RedirectableRequest in a Set and clear kAxiosCurrentReq for all on req.once('close', ...).
    • Remove per-redirect close listener that stacked because follow-redirects re-emits socket for each hop.
    • Prevent stale kAxiosCurrentReq on earlier-hop sockets returned to the keep‑alive pool.
  • Reasoning
    • Avoids listener accumulation at >= 11 redirects and eliminates misattributed idle-pool errors from stale refs.
  • Additional context
    • No API changes. Improves stability for long redirect chains in axios’s Node HTTP adapter.

Docs

  • Add a note in /docs/ under redirects/HTTP adapter that long redirect chains no longer stack listeners or leak socket refs; high maxRedirects values are safe.

Testing

  • Added tests:
    • No MaxListenersExceededWarning when following 11+ redirects.
    • Close listeners on the outer request stay bounded across 20 redirects.
  • No changes to existing tests.

Semantic version impact

  • Patch: bug fix with no breaking changes.

Written for commit fbf7ec7. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 3/5

  • There is a medium-severity, high-confidence cleanup bug in lib/adapters/http.js: on close, only the final redirect socket is disassociated, leaving stale kAxiosCurrentReq references on earlier redirect-hop sockets.
  • This creates a concrete regression risk around connection/socket lifecycle handling during redirects, so the change carries some user-impacting risk until cleanup is applied consistently across hops.
  • Pay close attention to lib/adapters/http.js - ensure socket disassociation runs for every redirect hop, not just the last request socket.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/adapters/http.js">

<violation number="1" location="lib/adapters/http.js:986">
P2: Only the last redirect socket is disassociated on close, leaving stale `kAxiosCurrentReq` on earlier hop sockets.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/adapters/http.js Outdated
@jasonsaayman
Copy link
Copy Markdown
Member Author

@cubic-dev-ai please review again

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 24, 2026

@cubic-dev-ai please review again

@jasonsaayman I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@jasonsaayman jasonsaayman merged commit e6a6241 into v1.x Apr 24, 2026
26 checks passed
@jasonsaayman jasonsaayman deleted the fix/maxlistenersexceededwarning-occurs-when-single-request-follows-11-redirects branch April 24, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TLSSocket MaxListenersExceededWarning under concurrent keep-alive requests since v1.15.1 (PR #10576)

1 participant