Skip to content
New issue

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

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

Already on GitHub? # to your account

rename maxKeepAliveTimeout to keepAliveMaxTimeout #359

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Options:
- `keepAlive: Boolean`, enable or disable keep alive connections.
Default: `true`.

- `maxKeepAliveTimeout: Number`, the maximum allowed `idleTimeout` when overriden by
- `keepAliveMaxTimeout: Number`, the maximum allowed `idleTimeout` when overriden by
*keep-alive* hints from the server.
Default: `600e3` milliseconds (10min).

Expand Down
13 changes: 7 additions & 6 deletions lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const {
kKeepAliveTimeout,
kMaxHeadersSize,
kHeadersTimeout,
kMaxKeepAliveTimeout,
kKeepAliveMaxTimeout,
kKeepAliveTimeoutThreshold,
kKeepAlive
} = require('./symbols')
Expand All @@ -66,11 +66,12 @@ class Client extends EventEmitter {
socketTimeout,
idleTimeout,
maxKeepAliveTimeout,
keepAlive,
keepAliveMaxTimeout = maxKeepAliveTimeout,
keepAliveTimeoutThreshold,
socketPath,
requestTimeout,
pipelining,
keepAlive,
tls
} = {}) {
super()
Expand Down Expand Up @@ -115,8 +116,8 @@ class Client extends EventEmitter {
throw new InvalidArgumentError('invalid idleTimeout')
}

if (maxKeepAliveTimeout != null && (!Number.isFinite(maxKeepAliveTimeout) || maxKeepAliveTimeout <= 0)) {
throw new InvalidArgumentError('invalid maxKeepAliveTimeout')
if (keepAliveMaxTimeout != null && (!Number.isFinite(keepAliveMaxTimeout) || keepAliveMaxTimeout <= 0)) {
throw new InvalidArgumentError('invalid keepAliveMaxTimeout')
}

if (keepAlive != null && typeof keepAlive !== 'boolean') {
Expand All @@ -143,8 +144,8 @@ class Client extends EventEmitter {
this[kUrl] = url
this[kSocketPath] = socketPath
this[kSocketTimeout] = socketTimeout == null ? 30e3 : socketTimeout
this[kMaxKeepAliveTimeout] = maxKeepAliveTimeout == null ? 600e3 : maxKeepAliveTimeout
this[kIdleTimeout] = idleTimeout == null ? 4e3 : idleTimeout
this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
this[kKeepAliveTimeoutThreshold] = keepAliveTimeoutThreshold == null ? 1e3 : keepAliveTimeoutThreshold
this[kKeepAliveTimeout] = this[kIdleTimeout]
this[kKeepAlive] = keepAlive == null ? true : keepAlive
Expand Down Expand Up @@ -512,7 +513,7 @@ class Parser extends HTTPParser {
if (Number.isFinite(keepAliveTimeout)) {
const timeout = Math.min(
keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
client[kMaxKeepAliveTimeout]
client[kKeepAliveMaxTimeout]
)
if (timeout < 1e3) {
client[kReset] = true
Expand Down
4 changes: 2 additions & 2 deletions lib/core/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports = {
kPause: Symbol('pause'),
kSocketTimeout: Symbol('socket timeout'),
kIdleTimeout: Symbol('idle timeout'),
kMaxKeepAliveTimeout: Symbol('max keep alive timeout'),
kKeepAliveTimeoutThreshold: Symbol('keep alive timeout threshold'),
kRequestTimeout: Symbol('request timeout'),
kKeepAliveMaxTimeout: Symbol('max keep alive timeout'),
kKeepAliveTimeoutThreshold: Symbol('keep alive timeout threshold'),
kKeepAliveTimeout: Symbol('keep alive timeout'),
kKeepAlive: Symbol('keep alive'),
kServerName: Symbol('server name'),
Expand Down
8 changes: 4 additions & 4 deletions test/client-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,20 @@ test('invalid options throws', (t) => {

try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
maxKeepAliveTimeout: 'asd'
keepAliveMaxTimeout: 'asd'
}) // eslint-disable-line
} catch (err) {
t.ok(err instanceof errors.InvalidArgumentError)
t.strictEqual(err.message, 'invalid maxKeepAliveTimeout')
t.strictEqual(err.message, 'invalid keepAliveMaxTimeout')
}

try {
new Client(new URL('http://localhost:200'), { // eslint-disable-line
maxKeepAliveTimeout: 0
keepAliveMaxTimeout: 0
}) // eslint-disable-line
} catch (err) {
t.ok(err instanceof errors.InvalidArgumentError)
t.strictEqual(err.message, 'invalid maxKeepAliveTimeout')
t.strictEqual(err.message, 'invalid keepAliveMaxTimeout')
}

try {
Expand Down
2 changes: 1 addition & 1 deletion test/client-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test('keep-alive max keepalive', (t) => {
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
idleTimeout: 30e3,
maxKeepAliveTimeout: 1e3
keepAliveMaxTimeout: 1e3
})
t.teardown(client.destroy.bind(client))

Expand Down