Skip to content

Commit 62e7e2b

Browse files
committed
Ensure connections are closed
1 parent 96cfb6a commit 62e7e2b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/connection.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function Connection(options = {}) {
137137
: (messages.push(buffer), connect())
138138
} catch (err) {
139139
query.reject(err)
140+
idle()
140141
}
141142
}
142143

@@ -178,8 +179,10 @@ function Connection(options = {}) {
178179
}
179180

180181
function idle() {
181-
clearTimeout(timer)
182-
timer = setTimeout(socket.end, idle_timeout * 1000)
182+
if (idle_timeout && !backend.query && queries.length === 0) {
183+
clearTimeout(timer)
184+
timer = setTimeout(socket.end, idle_timeout * 1000)
185+
}
183186
}
184187

185188
function onready(err) {
@@ -204,7 +207,7 @@ function Connection(options = {}) {
204207
}
205208

206209
backend.query = backend.error = null
207-
idle_timeout && queries.length === 0 && idle()
210+
idle()
208211

209212
if (!open) {
210213
messages.forEach(socket.write)
@@ -303,6 +306,7 @@ function postgresSocket(options, {
303306
socket.write(frontend.connect(options))
304307
} catch (e) {
305308
error(e)
309+
socket.end()
306310
}
307311
}
308312

0 commit comments

Comments
 (0)