Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/pg/lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ class Connection extends EventEmitter {
}

sync() {
this._ending = true
// Sync is the extended-query protocol barrier, not a disconnect.
// Only end()/Terminate (and connect-timeout teardown) should set _ending.
this._send(syncBuffer)
}

Expand Down
22 changes: 22 additions & 0 deletions packages/pg/test/unit/connection/error-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ suite.test('connection emits ECONNRESET errors during normal operation', functio
con.stream.emit('error', e)
})

suite.test('connection emits ECONNRESET errors after Sync (Sync is not disconnect)', function (done) {
const con = new Connection({ stream: new MemoryStream() })
con.connect()
// Extended-query Sync used to incorrectly set _ending and swallow resets (#3769)
con.sync()
assert.equal(con._ending, false)
assert.emits(con, 'error', function (err) {
assert.equal(err.code, 'ECONNRESET')
done()
})
const e = new Error('Connection Reset')
e.code = 'ECONNRESET'
con.stream.emit('error', e)
})

suite.test('connection does not set _ending when calling sync()', function () {
const con = new Connection({ stream: new MemoryStream() })
con.connect()
con.sync()
assert.equal(con._ending, false)
})

suite.test('connection does not emit ECONNRESET errors during disconnect', function (done) {
const con = new Connection({ stream: new MemoryStream() })
con.connect()
Expand Down
Loading