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

"Packet size mismatch!" on dropping mongodb collection #2812

Open
gedaiu opened this issue Jan 5, 2025 · 2 comments · May be fixed by #2813
Open

"Packet size mismatch!" on dropping mongodb collection #2812

gedaiu opened this issue Jan 5, 2025 · 2 comments · May be fixed by #2813

Comments

@gedaiu
Copy link
Contributor

gedaiu commented Jan 5, 2025

Any ideas on how can I fix this issue? It looks like it is a Driver problem:

/// test message error
unittest {
  auto client = connectMongoDB("127.0.0.1");
  auto chunks = client.getCollection("test.fs.chunks");

  chunks.drop;
}

throws:

core.exception.AssertError: Packet size mismatch! Expected 38 bytes, but read 20.
Stack trace:
-------------------
...
0xe058dc _d_assert_msg
0x74d7a4 @safe int vibe.db.mongo.connection.MongoConnection.recvMsg!(true).recvMsg(int, scope void delegate(uint, vibe.data.bson.Bson) @safe, scope void delegate(scope const(char)[], int) @safe, scope void delegate(scope const(char)[], vibe.data.bson.Bson) @safe) (../vibe-d/mongodb/vibe/db/mongo/connection.d:788)
0x74f5bf @safe vibe.data.bson.Bson vibe.db.mongo.connection.MongoConnection.runCommandImpl!(vibe.data.bson.Bson, vibe.db.mongo.connection.MongoDriverException).runCommandImpl(immutable(char)[], vibe.data.bson.Bson, bool, immutable(char)[], immutable(char)[], ulong) (../vibe-d/mongodb/vibe/db/mongo/connection.d:432)
0x74f451 @safe vibe.data.bson.Bson vibe.db.mongo.connection.MongoConnection.runCommand!(vibe.data.bson.Bson, vibe.db.mongo.connection.MongoDriverException).runCommand(immutable(char)[], vibe.data.bson.Bson, immutable(char)[], immutable(char)[], ulong) (../vibe-d/mongodb/vibe/db/mongo/connection.d:387)
0xc5488b @safe vibe.data.bson.Bson vibe.db.mongo.database.MongoDatabase.runCommandChecked!(vibe.db.mongo.collection.MongoCollection.drop().CMD, vibe.db.mongo.connection.MongoDriverException).runCommandChecked(vibe.db.mongo.collection.MongoCollection.drop().CMD, immutable(char)[], immutable(char)[], ulong) (../vibe-d/mongodb/vibe/db/mongo/database.d:160)
0xc3eef5 @safe void vibe.db.mongo.collection.MongoCollection.drop() (../vibe-d/mongodb/vibe/db/mongo/collection.d:1238)
0x964f8f void tests.crate.resources.gridfs.__unittest_L52_C1() (tests/crate/resources/gridfs.d:56)

mongo db logs:

{"t":{"$date":"2025-01-05T12:56:14.368+01:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:38847","uuid":{"uuid":{"$uuid":"21e52944-2c9b-4cb0-896b-08886770842d"}},"connectionId":6,"connectionCount":1}}
{"t":{"$date":"2025-01-05T12:56:14.368+01:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn6","msg":"client metadata","attr":{"remote":"127.0.0.1:38847","client":"conn6","negotiatedCompressors":[],"doc":{"platform":"Digital Mars D 2.109","os":{"type":"linux","architecture":"x86_64 littleEndian"},"driver":{"version":"2.2.0","name":"vibe.db.mongo"}}}}
{"t":{"$date":"2025-01-05T12:56:14.368+01:00"},"s":"I",  "c":"NETWORK",  "id":6788700, "ctx":"conn6","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":0}}
{"t":{"$date":"2025-01-05T12:56:14.368+01:00"},"s":"I",  "c":"COMMAND",  "id":518070,  "ctx":"conn6","msg":"CMD: drop","attr":{"namespace":"test.fs.chunks"}}
{"t":{"$date":"2025-01-05T12:56:14.393+01:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn6","msg":"Connection ended","attr":{"remote":"127.0.0.1:38847","uuid":{"uuid":{"$uuid":"21e52944-2c9b-4cb0-896b-08886770842d"}},"connectionId":6,"connectionCount":0}}
❯ mongod --version
db version v7.0.16
Build Info: {
    "version": "7.0.16",
    "gitVersion": "18b949444cfdaa88e30b0e10243bc18268251c1f",
    "openSSLVersion": "OpenSSL 3.2.2 4 Jun 2024",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel90",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
@gedaiu gedaiu changed the title issue with dropping collection "Packet size mismatch!" on dropping mongodb collection Jan 5, 2025
@gedaiu
Copy link
Contributor Author

gedaiu commented Jan 10, 2025

@WebFreak001 @s-ludwig, do you have any thoughts on how I can fix this issue?

@WebFreak001
Copy link
Contributor

WebFreak001 commented Jan 10, 2025

assert(bytes_read + msglen == m_bytesRead,

seems to be a malformed packet

  1. this shouldn't be an assert but an exception/enforce
  2. the packet format is defined here: https://github.com/mongodb/specifications/blob/ce35696db1c8da0e15a067b8022c853f1d6d1292/source/message/OP_MSG.md

I think the while code is wrong, instead of
while (m_bytesRead - bytes_read < sectionLength) {
it should probably be
while (m_bytesRead - bytes_read < msglen) {
or instead make the variable bytes_read (which has a bad name) start after all the flags, since that is what sectionLength calculates.

Feel free to try out that while loop instead and see if that fixes it.

If you open a PR, please also rename bytes_read, it's a bad variable name (it should be something like packet_start_index or similar, since it's a snapshot of where we were before reading anything from the packet to see if we read everything)

The sectionLength will most likely be obsolete and can be removed.

@gedaiu gedaiu linked a pull request Jan 11, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants