{"record":{"id":"4bedeae609815013","repo":"dotnet/aspnetcore","slug":"invalid-payload-for-completion-message","errorCode":null,"errorMessage":"Invalid payload for Completion message.","messagePattern":"Invalid payload for Completion message\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts","lineNumber":232,"sourceCode":"\n    private _createStreamItemMessage(headers: MessageHeaders, properties: any[]): StreamItemMessage {\n        // check minimum length to allow protocol to add items to the end of objects in future releases\n        if (properties.length < 4) {\n            throw new Error(\"Invalid payload for StreamItem message.\");\n        }\n\n        return {\n            headers,\n            invocationId: properties[2],\n            item: properties[3],\n            type: MessageType.StreamItem,\n        } as StreamItemMessage;\n    }\n\n    private _createCompletionMessage(headers: MessageHeaders, properties: any[]): CompletionMessage {\n        // check minimum length to allow protocol to add items to the end of objects in future releases\n        if (properties.length < 4) {\n            throw new Error(\"Invalid payload for Completion message.\");\n        }\n\n        const resultKind = properties[3];\n\n        if (resultKind !== this._voidResult && properties.length < 5) {\n            throw new Error(\"Invalid payload for Completion message.\");\n        }\n\n        let error: string | undefined;\n        let result: any;\n\n        switch (resultKind) {\n            case this._errorResult:\n                error = properties[4];\n                break;\n            case this._nonVoidResult:\n                result = properties[4];\n                break;","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts#L214-L250","documentation":"Thrown by _createCompletionMessage (first check) when the decoded properties array has fewer than 4 elements. A Completion message is [MessageType.Completion, headers, invocationId, resultKind, result?]. resultKind (properties[3]) is mandatory — fewer than 4 elements means the result kind is absent.","triggerScenarios":"A Completion frame missing the resultKind byte; corrupt bytes decoding to a short array typed as Completion; a non-conforming server sending an incompletely-encoded completion.","commonSituations":"Server-side completion serialization bug; protocol version mismatch; wire corruption after an invocation.","solutions":["Verify the server's completion encoder includes the resultKind slot.","Match SignalR protocol versions between client and server.","Reconnect the HubConnection; the invocation whose completion was malformed will not resolve, so callers awaiting it should also be notified."],"exampleFix":"// before\n// server emits [3, {}, '42'] — missing resultKind → throws\n\n// after — server must emit [3, {}, '42', resultKind, ...]\n// e.g. void result: [3, {}, '42', 0]","handlingStrategy":"validation","validationCode":"function isValidCompletionProperties(p: unknown[]): boolean {\n  return p.length >= 4;\n}","typeGuard":"function isCompletionPayload(p: unknown[]): p is [number, unknown, string, number, unknown?] {\n  return p.length >= 4;\n}","tryCatchPattern":"try { return protocol.parseMessages(buf, logger); }\ncatch (e) {\n  if (/Invalid payload for Completion/.test((e as Error).message)) {\n    logger.log(LogLevel.Error, 'Malformed Completion — reconnecting');\n    await connection.stop(); await connection.start();\n  } else throw e;\n}","preventionTips":["Server must always emit the resultKind slot for completions.","Align client/server SignalR protocol versions.","Notify awaiting callers when a completion cannot be parsed."],"tags":["signalr","messagepack","completion","validation","wire-format"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}