Skip to content

Commit

Permalink
Merge pull request #1081 from benbotto/keep-alive
Browse files Browse the repository at this point in the history
Keep alive
  • Loading branch information
sidorares authored Dec 13, 2019
2 parents d8cac2a + 288d997 commit f9b9f96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class Connection extends EventEmitter {
} else {
this.stream = opts.config.stream;
}

// Enable keep-alive on the socket. It's disabled by default, but the
// user can enable it and supply an initial delay.
if (typeof this.stream.setKeepAlive === 'function' && this.config.enableKeepAlive)
this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay);

this._internalId = _connectionId++;
this._commands = new Queue();
this._command = null;
Expand Down
4 changes: 4 additions & 0 deletions lib/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const validOptions = {
dateStrings: 1,
debug: 1,
decimalNumbers: 1,
enableKeepAlive: 1,
flags: 1,
host: 1,
insecureAuth: 1,
isServer: 1,
keepAliveInitialDelay: 1,
localAddress: 1,
maxPreparedStatements: 1,
multipleStatements: 1,
Expand Down Expand Up @@ -93,6 +95,8 @@ class ConnectionConfig {
this.debug = options.debug;
this.trace = options.trace !== false;
this.stringifyObjects = options.stringifyObjects || false;
this.enableKeepAlive = !!options.enableKeepAlive;
this.keepAliveInitialDelay = options.keepAliveInitialDelay || 0;
if (
options.timezone &&
!/^(?:local|Z|[ +-]\d\d:\d\d)$/.test(options.timezone)
Expand Down

0 comments on commit f9b9f96

Please sign in to comment.