Fix for interspersed messages

The way the messages were buffered caused interspersed messages to be
inserted in the middle of CopyData messages disrupting the normal COPY
TO flow.

This fixes it by consuming (adjusting offsets as appropriate) and just
logging them to console, effectively discarding them from the COPY
flow.
This commit is contained in:
Rafa de la Torre 2019-06-04 12:21:46 +02:00
parent be101502d9
commit 002a36bcfc

View File

@ -95,13 +95,20 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) {
length = chunk.readUInt32BE(offset+Byte1Len)
if(chunk.length >= (offset + Byte1Len + length)) {
offset += Byte1Len + Int32Len
if (needPush) {
var row = chunk.slice(offset, offset + length - Int32Len)
this.rowCount++
row.copy(buffer, buffer_offset);
buffer_offset += row.length;
var message = chunk.slice(offset, offset + length - Int32Len)
switch(messageCode) {
case code.CopyData:
this.rowCount++;
message.copy(buffer, buffer_offset);
buffer_offset += message.length;
break;
case code.ParameterStatus:
case code.NoticeResponse:
case code.NotificationResponse:
console.log("Got an interspersed message: " + message);
break;
}
offset += (length - Int32Len)
offset += (length - Int32Len);
} else {
// we need more chunks for a complete message
break;