From 002a36bcfcad68244d29af5e01cf0fecdf05868e Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Tue, 4 Jun 2019 12:21:46 +0200 Subject: [PATCH] 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. --- copy-to.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/copy-to.js b/copy-to.js index 5b843d3..c7d268f 100644 --- a/copy-to.js +++ b/copy-to.js @@ -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;