{"id":"d12a94b0d124567a","repo":"aio-libs/aiohttp","slug":"invalid-window-size","errorCode":null,"errorMessage":"Invalid window size","messagePattern":"Invalid window size","errorType":"exception","errorClass":"WSHandshakeError","httpStatus":null,"severity":"error","filePath":"aiohttp/_websocket/helpers.py","lineNumber":117,"sourceCode":"                    # Compress wbit 8 does not support in zlib\n                    # If compress level not support,\n                    # CONTINUE to next extension\n                    if compress > 15 or compress < 9:\n                        compress = 0\n                        continue\n                if match.group(1):\n                    notakeover = True\n                # Ignore regex group 5 & 6 for client_max_window_bits\n                break\n            else:\n                if match.group(6):\n                    compress = int(match.group(6))\n                    # Group5 must match if group6 matches\n                    # Compress wbit 8 does not support in zlib\n                    # If compress level not support,\n                    # FAIL the parse progress\n                    if compress > 15 or compress < 9:\n                        raise WSHandshakeError(\"Invalid window size\")\n                if match.group(2):\n                    notakeover = True\n                # Ignore regex group 5 & 6 for client_max_window_bits\n                break\n        # Return Fail if client side and not match\n        elif not isserver:\n            raise WSHandshakeError(\"Extension for deflate not supported\" + ext.group(1))\n\n    return compress, notakeover\n\n\ndef ws_ext_gen(\n    compress: int = 15, isserver: bool = False, server_notakeover: bool = False\n) -> str:\n    # client_notakeover=False not used for server\n    # compress wbit 8 does not support in zlib\n    if compress < 9 or compress > 15:\n        raise ValueError(","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/_websocket/helpers.py#L99-L135","documentation":"WSHandshakeError raised by ws_ext_parse() during the CLIENT side (isserver=False) of the permessage-deflate negotiation when the server's Sec-WebSocket-Extensions response advertises a client_max_window_bits value outside the valid 9-15 range. zlib cannot use wbits=8 and values above 15 are illegal, so aiohttp rejects the handshake rather than accepting a broken compression agreement. It is a hard handshake failure, not a warning.","triggerScenarios":"The server returns a header like 'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits=8' (or 16, or any value <9 or >15) and the client called session.ws_connect(url) with compression enabled (compress=15 default). ws_ext_parse parses group(6) from _WS_EXT_RE, sees the out-of-range value, and raises.","commonSituations":"Talking to a buggy/non-RFC-7692 server or gateway that mangles the deflate extension params; a custom server echoing back the client's offered window bits incorrectly; testing against a mock server that hard-codes an invalid wbits. The error appears at await session.ws_connect(...) time.","solutions":["Disable compression on the client to bypass the broken negotiation: await session.ws_connect(url, compress=0).","Wrap ws_connect in try/except WSHandshakeError and fall back to a non-compressed connection (retry with compress=0).","Fix the server/gateway so client_max_window_bits, if echoed, is in the 9-15 range or omitted entirely.","Report the non-compliant Sec-WebSocket-Extensions header to the server maintainer; capture the raw header to confirm the offending value."],"exampleFix":"# before\nws = await session.ws_connect('wss://buggy.example/feed')  # WSHandshakeError: Invalid window size\n\n# after\ntry:\n    ws = await session.ws_connect('wss://buggy.example/feed')\nexcept aiohttp.WSHandshakeError:\n    ws = await session.ws_connect('wss://buggy.example/feed', compress=0)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from aiohttp import WSHandshakeError\n\ntry:\n    ws = await session.ws_connect(url)\nexcept WSHandshakeError as exc:\n    # server advertised an invalid client_max_window_bits; retry uncompressed\n    ws = await session.ws_connect(url, compress=0)","preventionTips":["Catch WSHandshakeError around every ws_connect that leaves compression at the default.","Have a compress=0 fallback ready for servers with broken deflate negotiation.","Log the raw Sec-WebSocket-Extensions response header when a handshake fails to confirm the cause."],"tags":["websocket","handshake","compression","client","deflate"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}