Skip to content
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

Follow enableKeepAlive option #1258

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 5 additions & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ class Connection extends EventEmitter {
opts.config.host
);

// Enable keep-alive on the socket. It's disabled by default, but the
// user can enable it and supply an initial delay.
this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay);
// Enable keep-alive on the socket.
// It's enabled by default and user can supply an initial delay.
if (this.config.enableKeepAlive) {
this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay);
}
}
// if stream is a function, treat it as "stream agent / factory"
} else if (typeof opts.config.stream === 'function') {
Expand Down
3 changes: 2 additions & 1 deletion lib/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class ConnectionConfig {
this.debug = options.debug;
this.trace = options.trace !== false;
this.stringifyObjects = options.stringifyObjects || false;
this.enableKeepAlive = !!options.enableKeepAlive;
this.enableKeepAlive =
options.enableKeepAlive === undefined || options.enableKeepAlive;
this.keepAliveInitialDelay = options.keepAliveInitialDelay || 0;
if (
options.timezone &&
Expand Down
3 changes: 1 addition & 2 deletions typings/mysql/lib/Pool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ declare namespace Pool {
queueLimit?: number;

/**
* Enable keep-alive on the socket. It's disabled by default, but the
* user can enable it and supply an initial delay.
* Enable keep-alive on the socket. It's enabled by default.
*/
enableKeepAlive?: true;
Copy link

Choose a reason for hiding this comment

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

should be boolean instead of true

Copy link
Author

Choose a reason for hiding this comment

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

@irepela Thanks!


Expand Down