refactor(http): extract Http2Sessions into its own module#10861
Merged
jasonsaayman merged 4 commits intoMay 22, 2026
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 3 files
Confidence score: 3/5
- There is a concrete runtime risk in
lib/helpers/Http2Sessions.js: the idle-session timer is not cleared on session close, so a ref'edTimeoutmay keep Node’s event loop alive longer than expected. - The test coverage concern in
tests/unit/helpers/Http2Sessions.test.jsmeans a wrapper added during the firstgetSession()call could be missed, reducing confidence that this behavior is fully guarded against regression. - Given the medium severity (5/10) with high confidence, this looks like a manageable but real risk rather than a merge blocker.
- Pay close attention to
lib/helpers/Http2Sessions.js,tests/unit/helpers/Http2Sessions.test.js- timer cleanup on close and first-call assertion coverage are the key risk areas.
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/helpers/Http2Sessions.js">
<violation number="1" location="lib/helpers/Http2Sessions.js:95">
P2: Idle-session timer is never cleared when the session closes, so the ref'ed Timeout can keep the event loop alive until it expires.</violation>
</file>
<file name="tests/unit/helpers/Http2Sessions.test.js">
<violation number="1" location="tests/unit/helpers/Http2Sessions.test.js:165">
P2: The null-timeout test only compares `session.request` after a second lookup, so it would miss a wrapper installed during the first `getSession()` call.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Contributor
Author
Contributor
|
@carladams1299-lab I have started the AI code review. It will take a few minutes to complete. |
jasonsaayman
requested changes
May 7, 2026
Member
jasonsaayman
left a comment
There was a problem hiding this comment.
Thanks for the PR @carladams1299-lab, just the two issues
Contributor
Author
|
Hi, @jasonsaayman , |
jasonsaayman
added a commit
that referenced
this pull request
May 28, 2026
* refactor(http): extract Http2Sessions to lib/helpers for direct unit tests * fix(http2): clear pending idle timer when session closes * fix(http2): address review — strict mode, Node-only note, observable timer test --------- Co-authored-by: Jay <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract the
Http2Sessionsclass fromlib/adapters/http.jsinto its ownmodule at
lib/helpers/Http2Sessions.jsand add direct unit tests.The class is self-contained — it only depends on
http2andutil, with noclosure over per-request state — so the move requires no parameter threading
and no behavior change. The module-level
http2Sessionssingleton stays inhttp.jsas a one-line instantiation. Pulling the class out gives a realunit-test seam for session-pooling, timeout, and cleanup logic that was
previously only exercised end-to-end through the adapter.
Aligns with
AGENTS.mdguidance thatlib/helpers/should hold pieces thatare generic and reusable outside axios —
Http2Sessionsqualifies; nothingin it knows about axios.
Linked issue
Closes #10860
Changes
lib/helpers/Http2Sessions.js— class moved verbatim, with its ownhttp2/utilimports and a default export.lib/adapters/http.js: addedimport Http2Sessions from '../helpers/Http2Sessions.js', removed the inline class definition (~102 lines).tests/unit/helpers/Http2Sessions.test.js— 12 unit tests covering cache reuse, options-mismatch invalidation, skippingdestroyed/closedcached sessions, removal on sessionclose,sessionTimeoutclose-after-idle, timeout cancellation when a new stream opens, multi-stream lifetime, default 1000ms timeout, and thesessionTimeout: nullno-wrapper path.Checklist
Http2Sessions;npm run test:vitest:unitreports 49 files / 709 tests passing.index.d.tsandindex.d.cts) — N/A, internal refactor only; no public API, type, or error-code changes.http2Sessionssingleton, behavior, and call sites unchanged.Summary by cubic
Extracted the
Http2Sessionsclass intolib/helpers/Http2Sessions.jsfor direct unit testing and cleaned up session idle timers on close; no public API changes.Description
Http2Sessionstolib/helpers/Http2Sessions.jsand imported it inlib/adapters/http.js; the adapter-level singleton remains.closeevent fires.'use strict'and a Node-only note; relies onhttp2andutil.Docs
No user-facing changes. Optionally add a maintainer note in
/docs/thatHttp2Sessionslives underlib/helpers/.Testing
Added
tests/unit/helpers/Http2Sessions.test.jswith 14 unit tests covering cache reuse, option mismatches, destroyed/closed handling, removal onclose, idle timeout defaults and behavior, cancel on new stream, multi-stream lifecycle, thesessionTimeout: nullpath, and clearing the idle timer when the session closes.Semantic version impact
Patch: internal refactor and non-breaking bug fix.
Written for commit b827625. Summary will update on new commits. Review in cubic