Skip to content

Commit

Permalink
Fix Packet size mismatch! error on collection drop
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Jan 11, 2025
1 parent 1dffb74 commit 8f88a9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions mongodb/vibe/db/mongo/collection.d
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,15 @@ struct MongoCollection {
}
}

/// Drop a collection
@safe unittest {
import vibe.db.mongo.mongo;
auto client = connectMongoDB("127.0.0.1");
auto chunks = client.getCollection("test.fs.chunks");

chunks.drop;
}

/**
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.
Expand Down
8 changes: 4 additions & 4 deletions mongodb/vibe/db/mongo/connection.d
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ final class MongoConnection {
{
import std.traits;

auto bytes_read = m_bytesRead;
auto packet_start_index = m_bytesRead;
int msglen = recvInt();
int resid = recvInt();
int respto = recvInt();
Expand All @@ -731,7 +731,7 @@ final class MongoConnection {
sectionLength -= uint.sizeof; // CRC present

bool gotSec0;
while (m_bytesRead - bytes_read < sectionLength) {
while (m_bytesRead - packet_start_index < msglen) {
// TODO: directly deserialize from the wire
static if (!dupBson) {
ubyte[256] buf = void;
Expand Down Expand Up @@ -783,9 +783,9 @@ final class MongoConnection {
logDiagnostic("recvData: crc=%s (discarded)", crc);
}

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

return resid;
}
Expand Down

0 comments on commit 8f88a9c

Please sign in to comment.