Skip to content

doc: add default value for the timeout option of http.Agent in http.md #58018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

howiezhao
Copy link
Contributor

Add default value (0) for the timeout option of http.Agent in http.md

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. http Issues or PRs related to the http subsystem. labels Apr 25, 2025
Copy link
Contributor

@ShogunPanda ShogunPanda left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

LGTM with shortening the commit message (simply omitting in `http.md` should be sufficient).

@lpinca
Copy link
Member

lpinca commented Apr 25, 2025

The default value seems to actually be undefined.

// test.js
const http = require('http');

const agent = new http.Agent();

agent.createConnection = function (options) {
  console.log(options);
};

const request = http.request({
  agent,
  host: 'example.com'
});
$ node test.js 
[Object: null prototype] {
  agent: Agent {
    _events: [Object: null prototype] {
      free: [Function (anonymous)],
      newListener: [Function: maybeEnableKeylog]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    defaultPort: 80,
    protocol: 'http:',
    options: [Object: null prototype] { noDelay: true, path: null },
    requests: [Object: null prototype] {},
    sockets: [Object: null prototype] { 'example.com:80:': [] },
    freeSockets: [Object: null prototype] {},
    keepAliveMsecs: 1000,
    keepAlive: false,
    maxSockets: Infinity,
    maxFreeSockets: 256,
    scheduling: 'lifo',
    maxTotalSockets: Infinity,
    totalSocketCount: 0,
    createConnection: [Function (anonymous)],
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  host: 'example.com',
  port: 80,
  noDelay: true,
  path: null,
  servername: 'example.com',
  _agentKey: 'example.com:80:',
  encoding: null
}
@howiezhao
Copy link
Contributor Author

The default value seems to actually be undefined.

// test.js
const http = require('http');

const agent = new http.Agent();

agent.createConnection = function (options) {
  console.log(options);
};

const request = http.request({
  agent,
  host: 'example.com'
});
$ node test.js 
[Object: null prototype] {
  agent: Agent {
    _events: [Object: null prototype] {
      free: [Function (anonymous)],
      newListener: [Function: maybeEnableKeylog]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    defaultPort: 80,
    protocol: 'http:',
    options: [Object: null prototype] { noDelay: true, path: null },
    requests: [Object: null prototype] {},
    sockets: [Object: null prototype] { 'example.com:80:': [] },
    freeSockets: [Object: null prototype] {},
    keepAliveMsecs: 1000,
    keepAlive: false,
    maxSockets: Infinity,
    maxFreeSockets: 256,
    scheduling: 'lifo',
    maxTotalSockets: Infinity,
    totalSocketCount: 0,
    createConnection: [Function (anonymous)],
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  host: 'example.com',
  port: 80,
  noDelay: true,
  path: null,
  servername: 'example.com',
  _agentKey: 'example.com:80:',
  encoding: null
}

@lpinca Oh, It seems you are right.
I just saw the relevant logic of setting 0 in the code:

But this is just an implicit setting in the code.
Maybe I should close this PR, sorry.

@howiezhao howiezhao closed this Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. http Issues or PRs related to the http subsystem.
6 participants