{"id":"65fc76c57151825d","repo":"mongodb/node-mongodb-native","slug":"op-msg-payload-type-1-detected-unsupported-protoco","errorCode":null,"errorMessage":"OP_MSG Payload Type 1 detected unsupported protocol","messagePattern":"OP_MSG Payload Type 1 detected unsupported protocol","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"error","filePath":"src/cmap/commands.ts","lineNumber":751,"sourceCode":"    this.index = 4;\n\n    while (this.index < this.data.length) {\n      const payloadType = this.data[this.index++];\n      if (payloadType === 0) {\n        // BSON spec specifies that this is a 32-bit signed integer: https://bsonspec.org/spec.html#:~:text=%3A%3A%3D-,int32,-e_list%20unsigned_byte(0\n        // While allowing negative sizes seems odd, in practice we never expect a negative size. Also, the server's 16mb limit for BSON documents leaves plenty\n        // of room in an int32 to store a document of the max BSON size that the server supports\n        const bsonSize = readInt32LE(this.data, this.index);\n        const bin = this.data.subarray(this.index, this.index + bsonSize);\n\n        this.sections.push(bin);\n\n        this.index += bsonSize;\n      } else if (payloadType === 1) {\n        // It was decided that no driver makes use of payload type 1\n\n        // TODO(NODE-3483): Replace with MongoDeprecationError\n        throw new MongoRuntimeError('OP_MSG Payload Type 1 detected unsupported protocol');\n      }\n    }\n\n    this.parsed = true;\n\n    return this.sections[0];\n  }\n}\n\nconst MESSAGE_HEADER_SIZE = 16;\nconst COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compressorID\n\n/**\n * @internal\n */\nexport interface OpCompressesRequestOptions {\n  zlibCompressionLevel: number;\n  agreedCompressor: CompressorName;","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/commands.ts#L733-L769","documentation":"Thrown while parsing an incoming OP_MSG wire-protocol message when a section with payloadType === 1 is encountered. The MongoDB wire protocol defines payload type 0 (a single BSON document) and type 1 (a sequence of documents), but the Node.js team decided no driver code path produces or consumes type 1, so the parser refuses it. In practice the server never sends type 1 to this driver, so seeing this error indicates a non-conforming peer, a man-in-the-middle, or memory corruption on the stream.","triggerScenarios":"Hit inside OnDemandDocument.parse() (src/cmap/commands.ts:747-752) while decoding any server reply that arrives as OP_MSG. Fires the moment the parser reads a payloadType byte equal to 1 for any section of the message. Triggered by connection.command()/sendWire() reading a response from any operation (query, write, handshake, heartbeat).","commonSituations":"Pointing the driver at a non-MongoDB service that speaks a similar-but-wrong protocol; a corrupted TCP/TLS stream producing garbage framing bytes; an intercepting proxy or debugger that re-frames the wire message; extremely rarely, a server bug or a forged/modified message.","solutions":["Confirm the URI host:port points at a real mongod/mongos and not another database or HTTP service.","Disable any network proxies, debug proxies, or TLS-terminating middleboxes between the client and server and retry.","Check driver and server versions are compatible (run a supported server version >= 3.6 which speaks OP_MSG).","If reproducible, capture a packet capture (tcpdump) of the failing exchange and file a driver bug with the bytes preceding the error."],"exampleFix":"// before\nconst client = new MongoClient('mongodb://localhost:5432'); // wrong service\n\n// after\nconst client = new MongoClient('mongodb://localhost:27017'); // real mongod","handlingStrategy":"try-catch","validationCode":"// Validate the target is a MongoDB service before relying on it\nimport { MongoClient } from 'mongodb';\nasync function assertMongo(uri: string) {\n  const c = new MongoClient(uri);\n  try {\n    await c.db().admin().ping();\n    return true;\n  } catch (e) {\n    return false;\n  } finally {\n    await c.close().catch(() => {});\n  }\n}","typeGuard":"import { MongoRuntimeError } from 'mongodb';\nfunction isPayloadTypeError(e: unknown): e is MongoRuntimeError {\n  return e instanceof MongoRuntimeError &&\n    /Payload Type 1/.test(e.message);\n}","tryCatchPattern":"try {\n  await collection.findOne({}, { timeoutMS: 1000 });\n} catch (e) {\n  if (isPayloadTypeError(e)) {\n    // peer is not speaking expected OP_MSG framing; surface to ops\n    throw new Error('Target at ' + uri + ' is not a conforming MongoDB server');\n  }\n  throw e;\n}","preventionTips":["Always construct URIs from known mongod/mongos endpoints rather than discovery.","Avoid pointing MongoClient at opaque proxies that re-frame traffic.","Run an admin.ping() health check at startup to fail fast on wrong-target errors."],"tags":["wire-protocol","op-msg","runtime","network"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}