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) length = chunk.readUInt32BE(offset+Byte1Len)
if(chunk.length >= (offset + Byte1Len + length)) { if(chunk.length >= (offset + Byte1Len + length)) {
offset += Byte1Len + Int32Len offset += Byte1Len + Int32Len
if (needPush) { var message = chunk.slice(offset, offset + length - Int32Len)
var row = chunk.slice(offset, offset + length - Int32Len) switch(messageCode) {
this.rowCount++ case code.CopyData:
row.copy(buffer, buffer_offset); this.rowCount++;
buffer_offset += row.length; 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 { } else {
// we need more chunks for a complete message // we need more chunks for a complete message
break; break;