{"record":{"id":"9bab8098878d4ec4","repo":"sgl-project/sglang","slug":"message-size-length-exceeds-max-msg-size-byte","errorCode":null,"errorMessage":"Message size {length} exceeds {MAX_MSG_SIZE} byte cap","messagePattern":"Message size (.+?) exceeds (.+?) byte cap","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/weight_cache/protocol.py","lineNumber":224,"sourceCode":"\nMAX_MSG_SIZE = 256 * 1024 * 1024  # 256 MiB\n\n\ndef send_msg(sock, obj: Any) -> None:\n    \"\"\"Send a length-prefixed pickled message over a socket.\"\"\"\n    data = pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL)\n    header = struct.pack(\"!I\", len(data))\n    sock.sendall(header + data)\n\n\ndef recv_msg(sock) -> Any:\n    \"\"\"Receive a length-prefixed pickled message from a socket.\"\"\"\n    header = _recv_exact(sock, 4)\n    if header is None:\n        raise ConnectionError(\"Connection closed while reading message header\")\n    length = struct.unpack(\"!I\", header)[0]\n    if length > MAX_MSG_SIZE:\n        raise ValueError(f\"Message size {length} exceeds {MAX_MSG_SIZE} byte cap\")\n    data = _recv_exact(sock, length)\n    if data is None:\n        raise ConnectionError(\"Connection closed while reading message body\")\n    return safe_pickle_loads(data)\n\n\ndef _recv_exact(sock, n: int) -> Optional[bytes]:\n    \"\"\"Receive exactly n bytes from a socket.\"\"\"\n    buf = bytearray()\n    while len(buf) < n:\n        chunk = sock.recv(n - len(buf))\n        if not chunk:\n            return None\n        buf.extend(chunk)\n    return bytes(buf)\n\n\ndef compute_env_stamp() -> Dict[str, str]:","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/weight_cache/protocol.py#L206-L242","documentation":"recv_msg read a length prefix exceeding MAX_MSG_SIZE, so the framed message is rejected. This guards against corrupted frames or malicious/buggy peers sending huge payloads over the weight cache socket.","triggerScenarios":"Corrupted 4-byte big-endian length header (partial write, garbage bytes); peer sending a pickled message larger than the protocol cap.","commonSituations":"Protocol version mismatch between client and daemon; memory corruption or wrong-endianness framing; oversized fetch-state payload.","solutions":["Restart both client and daemon so they run the same sglang version","Reduce payload size (fewer tensors per message) or raise MAX_MSG_SIZE if legitimate","Check for socket data corruption / interleaved writers"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    recv_msg(sock)\nexcept ValueError as e:\n    if 'byte cap' in str(e): log_protocol_corruption()","preventionTips":["Run client and daemon on the same sglang version","Keep messages under MAX_MSG_SIZE"],"tags":["protocol","framing","size-limit"],"backgroundTag":"message-size-limit-exceeded","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}