pg 7.10.0 → 7.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/lib/client.js +12 -0
- package/lib/connection-parameters.js +19 -2
- package/lib/connection.js +4 -3
- package/lib/defaults.js +7 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,9 @@ For richer information consult the commit log on github with referenced pull req
|
|
|
4
4
|
|
|
5
5
|
We do not include break-fix version release in this file.
|
|
6
6
|
|
|
7
|
+
### 7.11.0
|
|
8
|
+
- Add support for [connection_timeout](https://github.com/brianc/node-postgres/pull/1847/files#diff-5391bde944956870128be1136e7bc176R63) and [keepalives_idle](https://github.com/brianc/node-postgres/pull/1847).
|
|
9
|
+
|
|
7
10
|
### 7.10.0
|
|
8
11
|
- Add support for [per-query types](https://github.com/brianc/node-postgres/pull/1825).
|
|
9
12
|
|
package/lib/client.js
CHANGED
|
@@ -44,6 +44,7 @@ var Client = function (config) {
|
|
|
44
44
|
stream: c.stream,
|
|
45
45
|
ssl: this.connectionParameters.ssl,
|
|
46
46
|
keepAlive: c.keepAlive || false,
|
|
47
|
+
keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
|
|
47
48
|
encoding: this.connectionParameters.client_encoding || 'utf8'
|
|
48
49
|
})
|
|
49
50
|
this.queryQueue = []
|
|
@@ -51,6 +52,7 @@ var Client = function (config) {
|
|
|
51
52
|
this.processID = null
|
|
52
53
|
this.secretKey = null
|
|
53
54
|
this.ssl = this.connectionParameters.ssl || false
|
|
55
|
+
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
util.inherits(Client, EventEmitter)
|
|
@@ -83,6 +85,14 @@ Client.prototype._connect = function (callback) {
|
|
|
83
85
|
}
|
|
84
86
|
this._connecting = true
|
|
85
87
|
|
|
88
|
+
var connectionTimeoutHandle
|
|
89
|
+
if (this._connectionTimeoutMillis > 0) {
|
|
90
|
+
connectionTimeoutHandle = setTimeout(() => {
|
|
91
|
+
con._ending = true
|
|
92
|
+
con.stream.destroy(new Error('timeout expired'))
|
|
93
|
+
}, this._connectionTimeoutMillis)
|
|
94
|
+
}
|
|
95
|
+
|
|
86
96
|
if (this.host && this.host.indexOf('/') === 0) {
|
|
87
97
|
con.connect(this.host + '/.s.PGSQL.' + this.port)
|
|
88
98
|
} else {
|
|
@@ -159,6 +169,7 @@ Client.prototype._connect = function (callback) {
|
|
|
159
169
|
return
|
|
160
170
|
}
|
|
161
171
|
this._connectionError = true
|
|
172
|
+
clearTimeout(connectionTimeoutHandle)
|
|
162
173
|
if (callback) {
|
|
163
174
|
return callback(err)
|
|
164
175
|
}
|
|
@@ -196,6 +207,7 @@ Client.prototype._connect = function (callback) {
|
|
|
196
207
|
con.removeListener('errorMessage', connectingErrorHandler)
|
|
197
208
|
con.on('error', connectedErrorHandler)
|
|
198
209
|
con.on('errorMessage', connectedErrorMessageHandler)
|
|
210
|
+
clearTimeout(connectionTimeoutHandle)
|
|
199
211
|
|
|
200
212
|
// process possible callback argument to Client#connect
|
|
201
213
|
if (callback) {
|
|
@@ -66,6 +66,22 @@ var ConnectionParameters = function (config) {
|
|
|
66
66
|
this.fallback_application_name = val('fallback_application_name', config, false)
|
|
67
67
|
this.statement_timeout = val('statement_timeout', config, false)
|
|
68
68
|
this.query_timeout = val('query_timeout', config, false)
|
|
69
|
+
|
|
70
|
+
if (config.connectionTimeoutMillis === undefined) {
|
|
71
|
+
this.connect_timeout = process.env.PGCONNECT_TIMEOUT || 0
|
|
72
|
+
} else {
|
|
73
|
+
this.connect_timeout = Math.floor(config.connectionTimeoutMillis / 1000)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (config.keepAlive === false) {
|
|
77
|
+
this.keepalives = 0
|
|
78
|
+
} else if (config.keepAlive === true) {
|
|
79
|
+
this.keepalives = 1
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof config.keepAliveInitialDelayMillis === 'number') {
|
|
83
|
+
this.keepalives_idle = Math.floor(config.keepAliveInitialDelayMillis / 1000)
|
|
84
|
+
}
|
|
69
85
|
}
|
|
70
86
|
|
|
71
87
|
// Convert arg to a string, surround in single quotes, and escape single quotes and backslashes
|
|
@@ -75,7 +91,7 @@ var quoteParamValue = function (value) {
|
|
|
75
91
|
|
|
76
92
|
var add = function (params, config, paramName) {
|
|
77
93
|
var value = config[paramName]
|
|
78
|
-
if (value) {
|
|
94
|
+
if (value !== undefined && value !== null) {
|
|
79
95
|
params.push(paramName + '=' + quoteParamValue(value))
|
|
80
96
|
}
|
|
81
97
|
}
|
|
@@ -87,8 +103,9 @@ ConnectionParameters.prototype.getLibpqConnectionString = function (cb) {
|
|
|
87
103
|
add(params, this, 'port')
|
|
88
104
|
add(params, this, 'application_name')
|
|
89
105
|
add(params, this, 'fallback_application_name')
|
|
106
|
+
add(params, this, 'connect_timeout')
|
|
90
107
|
|
|
91
|
-
var ssl = typeof this.ssl === 'object' ? this.ssl : { sslmode: this.ssl }
|
|
108
|
+
var ssl = typeof this.ssl === 'object' ? this.ssl : this.ssl ? { sslmode: this.ssl } : {}
|
|
92
109
|
add(params, ssl, 'sslmode')
|
|
93
110
|
add(params, ssl, 'sslca')
|
|
94
111
|
add(params, ssl, 'sslkey')
|
package/lib/connection.js
CHANGED
|
@@ -21,6 +21,7 @@ var Connection = function (config) {
|
|
|
21
21
|
config = config || {}
|
|
22
22
|
this.stream = config.stream || new net.Socket()
|
|
23
23
|
this._keepAlive = config.keepAlive
|
|
24
|
+
this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis
|
|
24
25
|
this.lastBuffer = false
|
|
25
26
|
this.lastOffset = 0
|
|
26
27
|
this.buffer = null
|
|
@@ -47,17 +48,17 @@ var Connection = function (config) {
|
|
|
47
48
|
util.inherits(Connection, EventEmitter)
|
|
48
49
|
|
|
49
50
|
Connection.prototype.connect = function (port, host) {
|
|
51
|
+
var self = this
|
|
52
|
+
|
|
50
53
|
if (this.stream.readyState === 'closed') {
|
|
51
54
|
this.stream.connect(port, host)
|
|
52
55
|
} else if (this.stream.readyState === 'open') {
|
|
53
56
|
this.emit('connect')
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
var self = this
|
|
57
|
-
|
|
58
59
|
this.stream.on('connect', function () {
|
|
59
60
|
if (self._keepAlive) {
|
|
60
|
-
self.stream.setKeepAlive(true)
|
|
61
|
+
self.stream.setKeepAlive(true, self._keepAliveInitialDelayMillis)
|
|
61
62
|
}
|
|
62
63
|
self.emit('connect')
|
|
63
64
|
})
|
package/lib/defaults.js
CHANGED
|
@@ -58,7 +58,13 @@ module.exports = {
|
|
|
58
58
|
statement_timeout: false,
|
|
59
59
|
|
|
60
60
|
// max miliseconds to wait for query to complete (client side)
|
|
61
|
-
query_timeout: false
|
|
61
|
+
query_timeout: false,
|
|
62
|
+
|
|
63
|
+
connect_timeout: 0,
|
|
64
|
+
|
|
65
|
+
keepalives: 1,
|
|
66
|
+
|
|
67
|
+
keepalives_idle: 0
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
var pgTypes = require('pg-types')
|