{"record":{"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/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/_websocket/helpers.py#L99-L135","documentation":"During the WebSocket handshake the *client* parses the server's `Sec-WebSocket-Extensions` response. For `permessage-deflate`, the `client_max_window_bits` value must be between 9 and 15 because zlib cannot operate with a window bit of 8. An out-of-range value raises `WSHandshakeError`, which aiohttp's client re-raises as `WSServerHandshakeError` (see `client.py:1159`).","triggerScenarios":"Calling `session.ws_connect(url, compress=15)` (or any truthy `compress`) against a server whose `Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits=N` has N < 9 or N > 15. Internally `ws_ext_parse(hdr, isserver=False)` raises at `helpers.py:117`.","commonSituations":"Interoperating with a buggy/non-conformant server that echoes an invalid window size; a custom server confusing zlib's general wbits (which allows 8 in some modes) with the WS deflate range; a proxy rewriting the header.","solutions":["Disable compression on the client to bypass negotiation entirely: `ws_connect(url, compress=0)` (or omit `compress`).","Fix the server to send a valid `client_max_window_bits` (9-15) or omit the value.","Catch `WSServerHandshakeError` and retry without compression as a fallback."],"exampleFix":"# before\nws = await session.ws_connect(url, compress=15)  # server sent client_max_window_bits=8 -> error\n# after\ntry:\n    ws = await session.ws_connect(url, compress=15)\nexcept aiohttp.WSServerHandshakeError:\n    ws = await session.ws_connect(url, compress=0)  # fall back to uncompressed","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ws = await session.ws_connect(url, compress=15)\nexcept aiohttp.WSServerHandshakeError as exc:\n    # server returned an unacceptable permessage-deflate extension\n    ws = await session.ws_connect(url, compress=0)","preventionTips":["Against third-party servers, retry with `compress=0` when the handshake fails.","Report `client_max_window_bits` outside 9-15 as a server bug (RFC 7692)."],"tags":["websocket","handshake","compression","deflate","window-bits"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}