From 8f88a9c7c001cc5740536860bc75bc4738a3be31 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Sat, 11 Jan 2025 14:13:30 +0100 Subject: [PATCH] Fix Packet size mismatch! error on collection drop --- mongodb/vibe/db/mongo/collection.d | 9 +++++++++ mongodb/vibe/db/mongo/connection.d | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mongodb/vibe/db/mongo/collection.d b/mongodb/vibe/db/mongo/collection.d index 92b4e9a56..57829b3cd 100644 --- a/mongodb/vibe/db/mongo/collection.d +++ b/mongodb/vibe/db/mongo/collection.d @@ -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. diff --git a/mongodb/vibe/db/mongo/connection.d b/mongodb/vibe/db/mongo/connection.d index a1cdffbb4..e1deeee9e 100644 --- a/mongodb/vibe/db/mongo/connection.d +++ b/mongodb/vibe/db/mongo/connection.d @@ -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(); @@ -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; @@ -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; }