Skip to content

Commit 1fa8df1

Browse files
committed
Fix Packet size mismatch! error on collection drop
1 parent 1dffb74 commit 1fa8df1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

mongodb/vibe/db/mongo/collection.d

+9
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,15 @@ struct MongoCollection {
13131313
}
13141314
}
13151315

1316+
/// Drop a collection
1317+
@safe unittest {
1318+
import vibe.db.mongo.mongo;
1319+
auto client = connectMongoDB("127.0.0.1");
1320+
auto chunks = client.getCollection("test.fs.chunks");
1321+
1322+
chunks.drop;
1323+
}
1324+
13161325
/**
13171326
Specifies a level of isolation for read operations. For example, you can use read concern to only read data that has propagated to a majority of nodes in a replica set.
13181327

mongodb/vibe/db/mongo/connection.d

+5-5
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ final class MongoConnection {
714714
{
715715
import std.traits;
716716

717-
auto bytes_read = m_bytesRead;
717+
auto packet_start_index = m_bytesRead;
718718
int msglen = recvInt();
719719
int resid = recvInt();
720720
int respto = recvInt();
@@ -731,8 +731,8 @@ final class MongoConnection {
731731
sectionLength -= uint.sizeof; // CRC present
732732

733733
bool gotSec0;
734-
while (m_bytesRead - bytes_read < sectionLength) {
735-
// TODO: directly deserialize from the wire
734+
while (m_bytesRead - packet_start_index < msglen) {
735+
// TODO: directly deserialize from the wire
736736
static if (!dupBson) {
737737
ubyte[256] buf = void;
738738
ubyte[] bufsl = buf;
@@ -783,9 +783,9 @@ final class MongoConnection {
783783
logDiagnostic("recvData: crc=%s (discarded)", crc);
784784
}
785785

786-
assert(bytes_read + msglen == m_bytesRead,
786+
assert(packet_start_index + msglen == m_bytesRead,
787787
format!"Packet size mismatch! Expected %s bytes, but read %s."(
788-
msglen, m_bytesRead - bytes_read));
788+
msglen, m_bytesRead - packet_start_index));
789789

790790
return resid;
791791
}

0 commit comments

Comments
 (0)