Skip to content

Commit 9b3346c

Browse files
committed
[CONJS-278] multiple part query (query bigger than 16M) wrongly reuse 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.
1 parent df707b3 commit 9b3346c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/io/packet-output-stream.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ class PacketOutputStream {
668668
//if last packet fill the max size, must send an empty com to indicate that command end.
669669
this.writeEmptyPacket();
670670
}
671+
this.buf = this.createBufferWithMinSize(remainingLen);
671672
this.pos = 4;
672673
}
673674
}
@@ -700,9 +701,24 @@ class PacketOutputStream {
700701
//if last packet fill the max size, must send an empty com to indicate that command end.
701702
this.writeEmptyPacket();
702703
}
704+
this.buf = this.createBufferWithMinSize(remainingLen);
703705
this.pos = 4;
704706
}
705707

708+
createBufferWithMinSize(remainingLen) {
709+
let newCapacity;
710+
if (remainingLen + this.pos < MEDIUM_BUFFER_SIZE) {
711+
newCapacity = MEDIUM_BUFFER_SIZE;
712+
} else if (remainingLen + this.pos < LARGE_BUFFER_SIZE) {
713+
newCapacity = LARGE_BUFFER_SIZE;
714+
} else if (remainingLen + this.pos < BIG_BUFFER_SIZE) {
715+
newCapacity = BIG_BUFFER_SIZE;
716+
} else {
717+
newCapacity = MAX_BUFFER_SIZE;
718+
}
719+
return Buffer.allocUnsafe(newCapacity);
720+
}
721+
706722
fastFlushDebug(cmd, packet) {
707723
this.stream.writeBuf(packet, cmd);
708724
this.stream.flush(true, cmd);

0 commit comments

Comments
 (0)