Skip to content

fix: closing session (http2) in removeSession()#7457

Merged
DigitalBrainJS merged 2 commits intoaxios:v1.xfrom
fedotov:fix-closing-connection-on-remove-session
Mar 6, 2026
Merged

fix: closing session (http2) in removeSession()#7457
DigitalBrainJS merged 2 commits intoaxios:v1.xfrom
fedotov:fix-closing-connection-on-remove-session

Conversation

@fedotov
Copy link
Copy Markdown
Contributor

@fedotov fedotov commented Feb 28, 2026

Problem

For http2 requests with defined sessionTimeout connection is not closed after the timeout and if there are no new requests, so it is wasted resources. Code to reproduce:

const axios = require('axios');

async function main() {
    const instance = axios.create( {
        maxRedirects: 0,
        httpVersion: 2,
        http2Options: {
            sessionTimeout: 5000,
            rejectUnauthorized: false,
        },
    });

    const response = await instance.request({ url: 'https://example.com/' });
    console.log(response.status, response.data.length);
}

main()
    .catch(console.error);

Without the fix, after the request and 5sec timeout application still running, because underlying connection is still open and Nodejs cannot quit (only server can close it).
With the fix the application is closed after 5sec.


Summary by cubic

Closes idle HTTP/2 sessions in removeSession() after sessionTimeout to prevent leaked connections. Frees resources and lets Node exit when idle.

Description

  • Summary of changes
    • Call session.close() in Http2Sessions.removeSession() if the session isn’t already closed.
  • Reasoning
    • Idle HTTP/2 sessions stayed open after timeout, keeping the process alive.
  • Additional context
    • Affects HTTP/2 only when http2Options.sessionTimeout is set. No API changes.

Testing

  • Added unit test in test/unit/adapters/http.js that makes an HTTP/2 request with sessionTimeout, listens for the 'close' event, waits past the timeout, and asserts the session closed.

Written for commit dbee25b. 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.

No issues found across 2 files

Confidence score: 5/5

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

@fedotov fedotov force-pushed the fix-closing-connection-on-remove-session branch from 992228b to 9f5eb28 Compare March 2, 2026 08:23
@DigitalBrainJS DigitalBrainJS merged commit f7a4ee2 into axios:v1.x Mar 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants