{"record":{"id":"662de879cf945303","repo":"python/cpython","slug":"high-r-must-be-low-r-must-be-0","errorCode":null,"errorMessage":"high (%r) must be >= low (%r) must be >= 0","messagePattern":"high \\(%r\\) must be >= low \\(%r\\) must be >= 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/sslproto.py","lineNumber":76,"sourceCode":"    return sslcontext\n\n\ndef add_flowcontrol_defaults(high, low, kb):\n    if high is None:\n        if low is None:\n            hi = kb * 1024\n        else:\n            lo = low\n            hi = 4 * lo\n    else:\n        hi = high\n    if low is None:\n        lo = hi // 4\n    else:\n        lo = low\n\n    if not hi >= lo >= 0:\n        raise ValueError('high (%r) must be >= low (%r) must be >= 0' %\n                         (hi, lo))\n\n    return hi, lo\n\n\nclass _SSLProtocolTransport(transports._FlowControlMixin,\n                            transports.Transport):\n\n    _start_tls_compatible = True\n    _sendfile_compatible = constants._SendfileMode.FALLBACK\n\n    def __init__(self, loop, ssl_protocol):\n        self._loop = loop\n        self._ssl_protocol = ssl_protocol\n        self._closed = False\n\n    def get_extra_info(self, name, default=None):\n        \"\"\"Get optional transport information.\"\"\"","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/sslproto.py#L58-L94","documentation":"Raised by add_flowcontrol_defaults() in asyncio.sslproto as ValueError when the computed flow-control watermarks violate hi >= lo >= 0. These high/low watermarks govern pause_writing()/resume_writing() backpressure on SSL transports; a high watermark smaller than the low watermark, or a negative value, is nonsensical and rejected.","triggerScenarios":"Creating an SSL-backed endpoint with explicit watermark kwargs where high < low or either is negative — e.g. passing high=4096, low=8192, or high=-1 — through APIs that forward to _SSLProtocol (loop.start_tls / internal protocol creation with high/low arguments).","commonSituations":"Tuning write-buffer watermarks for streaming protocols and swapping the high/low values; passing 0 or negative sentinels intended to mean 'unlimited'; configuration typos in transport tuning dicts.","solutions":["Ensure 0 <= low <= high in whatever config produces the watermarks; validate before passing them on.","Remember the defaulting rules: low=None -> high//4; when only kb is given, low=kb*1024 and high=4*low — prefer passing only one bound.","Omit high/low entirely unless you specifically need custom backpressure thresholds."],"exampleFix":"// before\nawait loop.start_tls(transport, protocol, ctx, high=4096, low=8192)\n# ValueError: high (4096) must be >= low (8192) must be >= 0\n\n// after\nawait loop.start_tls(transport, protocol, ctx, high=32768, low=8192)","handlingStrategy":"validation","validationCode":"def valid_watermarks(high, low):\n    if low is None:\n        low = high // 4\n    return high >= low >= 0\n\nassert valid_watermarks(32768, 8192)  # ok\n# only pass kwargs that pass this check to start_tls/protocol factories","typeGuard":"def are_valid_watermarks(high, low) -> bool:\n    if high is None or high < 0:\n        return False\n    eff_low = high // 4 if low is None else low\n    return high >= eff_low >= 0","tryCatchPattern":"try:\n    await loop.start_tls(transport, protocol, ctx, high=h, low=l)\nexcept ValueError as e:\n    if 'must be >=' in str(e):\n        await loop.start_tls(transport, protocol, ctx)  # sane defaults\n    else:\n        raise","preventionTips":["Prefer supplying only one watermark bound and let asyncio derive the other.","Validate 0 <= low <= high in config loaders before use.","Document that 'low' pauses resume and 'high' triggers pause_writing; ordering is fixed."],"tags":["asyncio","ssl","flow-control","backpressure","configuration"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}