Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Packet size mismatch! error on collection drop #2813

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ examples/bench-mongodb/bench-mongodb
examples/bench-urlrouter/bench-urlrouter
*.exe

tests/mongodb/collection/tests
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
7 changes: 7 additions & 0 deletions tests/mongodb/collection/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "tests",
"description": "High level MongoDB collection tests for vibe.d",
"dependencies": {
"vibe-d:mongodb": {"path": "../../../"}
}
}
39 changes: 39 additions & 0 deletions tests/mongodb/collection/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// Requires mongo service running on localhost with default port
/// Uses test database

module app;

import vibe.core.core;
import vibe.core.log;
import vibe.data.bson;
import vibe.db.mongo.mongo;

import std.algorithm : all, canFind, equal, map, sort;
import std.conv : to;
import std.encoding : sanitize;
import std.exception : assertThrown;


void runTest(ushort port)
{
MongoClient client = connectMongoDB("127.0.0.1", port);

/// Drop a collection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this test only testing dropping non-existent collections?

Should probably drop it twice just in case if it randomly existed beforehand on CI. It should behave the same both times after all.

Otherwise it might make sense to also create a collection here.

auto chunks = client.getCollection("test.fs.chunks");
chunks.drop;
}

int main(string[] args)
{
int ret = 0;
ushort port = args.length > 1
? args[1].to!ushort
: MongoClientSettings.defaultPort;
runTask(() nothrow {
try runTest(port);
catch (Exception e) assert(false, e.toString());
finally exitEventLoop(true);
});
runEventLoop();
return ret;
}
gedaiu marked this conversation as resolved.
Show resolved Hide resolved
Loading