Skip to content

Commit

Permalink
[CONJS-278] multiple part query (query bigger than 16M) wrongly reuse…
Browse files Browse the repository at this point in the history
… send buffer #274

When sending query with size bigger than 16M, buffer send in socket might sometime be reused. Node.js doesn't permit reusing of socket buffer. Query send is then wrong.
  • Loading branch information
rusher committed Feb 12, 2024
1 parent df707b3 commit 9b3346c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/io/packet-output-stream.js
Expand Up @@ -668,6 +668,7 @@ class PacketOutputStream {
//if last packet fill the max size, must send an empty com to indicate that command end.
this.writeEmptyPacket();
}
this.buf = this.createBufferWithMinSize(remainingLen);
this.pos = 4;
}
}
Expand Down Expand Up @@ -700,9 +701,24 @@ class PacketOutputStream {
//if last packet fill the max size, must send an empty com to indicate that command end.
this.writeEmptyPacket();
}
this.buf = this.createBufferWithMinSize(remainingLen);
this.pos = 4;
}

createBufferWithMinSize(remainingLen) {
let newCapacity;
if (remainingLen + this.pos < MEDIUM_BUFFER_SIZE) {
newCapacity = MEDIUM_BUFFER_SIZE;
} else if (remainingLen + this.pos < LARGE_BUFFER_SIZE) {
newCapacity = LARGE_BUFFER_SIZE;
} else if (remainingLen + this.pos < BIG_BUFFER_SIZE) {
newCapacity = BIG_BUFFER_SIZE;
} else {
newCapacity = MAX_BUFFER_SIZE;
}
return Buffer.allocUnsafe(newCapacity);
}

fastFlushDebug(cmd, packet) {
this.stream.writeBuf(packet, cmd);
this.stream.flush(true, cmd);
Expand Down

0 comments on commit 9b3346c

Please sign in to comment.