Adds handling for errors after initial response.
Includes a test.
This commit is contained in:
parent
1822f399d2
commit
1db9b3ec3d
10
copy-to.js
10
copy-to.js
@ -68,10 +68,14 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
|
|||||||
}
|
}
|
||||||
while((chunk.length - offset) > 5) {
|
while((chunk.length - offset) > 5) {
|
||||||
var messageCode = chunk[offset]
|
var messageCode = chunk[offset]
|
||||||
//complete
|
//complete or error
|
||||||
if(messageCode == code.c) {
|
if(messageCode == code.c || messageCode == code.E) {
|
||||||
this._detach()
|
this._detach()
|
||||||
this.connection.stream.unshift(chunk.slice(offset + 5))
|
if (messageCode == code.c) {
|
||||||
|
this.connection.stream.unshift(chunk.slice(offset + 5))
|
||||||
|
} else {
|
||||||
|
this.connection.stream.unshift(chunk.slice(offset))
|
||||||
|
}
|
||||||
this.push(null)
|
this.push(null)
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
@ -58,3 +58,26 @@ var testLeak = function(rounds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testLeak(5)
|
testLeak(5)
|
||||||
|
|
||||||
|
var testInternalPostgresError = function() {
|
||||||
|
var fromClient = client()
|
||||||
|
// This attempts to make an array that's too large, and should fail.
|
||||||
|
var txt = "COPY (SELECT array_agg(e) FROM (SELECT generate_series(1, 100000000) AS e) t) TO STDOUT"
|
||||||
|
|
||||||
|
var runStream = function(callback) {
|
||||||
|
var stream = fromClient.query(copy(txt))
|
||||||
|
stream.on('data', function(data) {
|
||||||
|
// Just throw away the data.
|
||||||
|
})
|
||||||
|
stream.on('error', callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
runStream(function(err) {
|
||||||
|
assert.notEqual(err, null)
|
||||||
|
expectedMessage = 'invalid memory alloc request size'
|
||||||
|
assert.notEqual(err.toString().indexOf(expectedMessage), -1, 'Error message should mention memory alloc request size.')
|
||||||
|
fromClient.end()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
testInternalPostgresError()
|
||||||
|
Loading…
Reference in New Issue
Block a user