{"record":{"id":"19eebd352650aeff","repo":"dotnet/aspnetcore","slug":"incomplete-message","errorCode":null,"errorMessage":"Incomplete message.","messagePattern":"Incomplete message\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr-protocol-msgpack/src/BinaryMessageFormat.ts","lineNumber":63,"sourceCode":"                numBytes++;\n            }\n            while (numBytes < Math.min(maxLengthPrefixSize, input.byteLength - offset) && (byteRead & 0x80) !== 0);\n\n            if ((byteRead & 0x80) !== 0 && numBytes < maxLengthPrefixSize) {\n                throw new Error(\"Cannot read message size.\");\n            }\n\n            if (numBytes === maxLengthPrefixSize && byteRead > 7) {\n                throw new Error(\"Messages bigger than 2GB are not supported.\");\n            }\n\n            if (uint8Array.byteLength >= (offset + numBytes + size)) {\n                // IE does not support .slice() so use subarray\n                result.push(uint8Array.slice\n                    ? uint8Array.slice(offset + numBytes, offset + numBytes + size)\n                    : uint8Array.subarray(offset + numBytes, offset + numBytes + size));\n            } else {\n                throw new Error(\"Incomplete message.\");\n            }\n\n            offset = offset + numBytes + size;\n        }\n\n        return result;\n    }\n}\n","sourceCodeStart":45,"sourceCodeEnd":72,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr-protocol-msgpack/src/BinaryMessageFormat.ts#L45-L72","documentation":"Thrown when the declared message size (decoded from the prefix) exceeds the remaining bytes in the input ArrayBuffer — i.e. the prefix says N more bytes follow, but only fewer are present. Standard SignalR partial-frame condition: the parser received the length header but not the full body.","triggerScenarios":"Feeding BinaryMessageFormat.parse a buffer that contains a complete prefix but a truncated body. Common in custom transports that do not wait for the full frame, or when the WebSocket emitted a partial message and the caller did not buffer across reads.","commonSituations":"Custom transport integration that calls parse per chunk instead of accumulating; the official client expects the transport layer (WebSocket.onmessage) to deliver complete frames so end-users usually see this only when intercepting the stream; server disconnected mid-write.","solutions":["Buffer incoming bytes until at least (prefixLength + declaredSize) bytes are available before calling parse.","If using the official signalr client and you see this, report it as a transport bug — the client should reassemble for you.","On a real disconnect, propagate the error and reconnect with a fresh HubConnection."],"exampleFix":"// before\nconst msgs = BinaryMessageFormat.parse(buffer); // partial body present\n\n// after — accumulate until the declared size is fully present\nconst prefix = readVarint(buffer);\nif (buffer.byteLength < prefix.bytes + prefix.size) {\n  return { needMore: true };\n}\nconst msgs = BinaryMessageFormat.parse(buffer);","handlingStrategy":"validation","validationCode":"// Pre-check that the declared body is fully present\nfunction hasFullBody(buf: Uint8Array, offset: number, maxLen: number): boolean {\n  let size = 0, numBytes = 0, byteRead;\n  do {\n    byteRead = buf[offset + numBytes];\n    size |= (byteRead & 0x7f) << (7 * numBytes);\n    numBytes++;\n  } while (numBytes < maxLen && (byteRead & 0x80) !== 0);\n  return buf.byteLength >= offset + numBytes + size;\n}","typeGuard":"function isCompleteFrame(buf: Uint8Array, offset: number): boolean {\n  // returns true only when prefix + declared body fit in buf\n  // (use hasFullBody implementation)\n  return hasFullBody(buf, offset, 5);\n}","tryCatchPattern":"try { return BinaryMessageFormat.parse(buf); }\ncatch (e) {\n  if (/Incomplete message/.test((e as Error).message)) {\n    pendingBuffer = concat(pendingBuffer, buf); return []; // wait for more\n  }\n  throw e;\n}","preventionTips":["Buffer until prefix bytes + declared size are available.","Prefer the official transport which reassembles frames automatically.","On disconnect, propagate the error and reconnect."],"tags":["signalr","messagepack","framing","partial-read","binary-protocol"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}