{"record":{"id":"751865e8193be280","repo":"dotnet/aspnetcore","slug":"invalid-payload-for-close-message","errorCode":null,"errorMessage":"Invalid payload for Close message.","messagePattern":"Invalid payload for Close message\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts","lineNumber":164,"sourceCode":"            case MessageType.Ping:\n                return this._createPingMessage(properties);\n            case MessageType.Close:\n                return this._createCloseMessage(properties);\n            case MessageType.Ack:\n                return this._createAckMessage(properties);\n            case MessageType.Sequence:\n                return this._createSequenceMessage(properties);\n            default:\n                // Future protocol changes can add message types, old clients can ignore them\n                logger.log(LogLevel.Information, \"Unknown message type '\" + messageType + \"' ignored.\");\n                return null;\n        }\n    }\n\n    private _createCloseMessage(properties: any[]): HubMessage {\n        // check minimum length to allow protocol to add items to the end of objects in future releases\n        if (properties.length < 2) {\n            throw new Error(\"Invalid payload for Close message.\");\n        }\n\n        return {\n            // Close messages have no headers.\n            allowReconnect: properties.length >= 3 ? properties[2] : undefined,\n            error: properties[1],\n            type: MessageType.Close,\n        } as HubMessage;\n    }\n\n    private _createPingMessage(properties: any[]): HubMessage {\n        // check minimum length to allow protocol to add items to the end of objects in future releases\n        if (properties.length < 1) {\n            throw new Error(\"Invalid payload for Ping message.\");\n        }\n\n        return {\n            // Ping messages have no headers.","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts#L146-L182","documentation":"Thrown by _createCloseMessage when the decoded properties array has fewer than 2 elements. A valid Close message is encoded as [MessageType.Close, error?, allowReconnect?] so it needs at least the type and the (possibly null) error slot. The minimum-length check lets the protocol add trailing fields in future versions without breaking.","triggerScenarios":"A Close frame encoded as a single-element array [MessageType.Close] (missing the error field); a malformed server-side Close serialization.","commonSituations":"Server and client protocol version mismatch where an older server omits the error slot; a custom server implementation building Close frames by hand; corrupted frame that lost trailing elements.","solutions":["Verify the server is a supported ASP.NET Core SignalR server emitting the documented Close frame shape.","Align client/server SignalR versions.","If you control the sender, ensure Close is encoded as [MessageType.Close, error] (at least 2 elements).","Wrap parseMessages in try/catch and trigger reconnection logic since a Close frame parse failure usually precedes disconnect anyway."],"exampleFix":"// before\nconst [_, resp] = handshake; // close arrives, parseMessages throws\n\n// after\ntry {\n  const messages = protocol.parseMessages(buffer, logger);\n} catch (e) {\n  if (/Close message/.test(e.message)) {\n    logger.log(LogLevel.Warning, 'Malformed Close frame; closing connection.');\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const messages = protocol.parseMessages(buffer, logger);\n} catch (e) {\n  if (/Close message/.test(e.message)) {\n    logger.log(LogLevel.Warning, 'Malformed Close frame; treating connection as closed.');\n    await connection.stop();\n  } else throw e;\n}","preventionTips":["Keep server and client SignalR versions aligned so the Close frame layout matches.","Wrap parseMessages in try/catch when operating on untrusted/transport data.","Log the offending frame for diagnosis when Close-frame corruption recurs."],"tags":["messagepack","close-message","validation","parsing","corruption"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}