{"record":{"id":"046b6d72aae60929","repo":"XX-net/XX-Net","slug":"gae-send-response-fail-r","errorCode":null,"errorMessage":"gae send response fail. %r","messagePattern":"gae send response fail\\. %r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/gae_proxy/local/gae_handler.py","lineNumber":209,"sourceCode":"\ndef send_response(wfile, status=404, headers={}, body=b''):\n    body = utils.to_bytes(body)\n    headers = dict((k.title(), v) for k, v in list(headers.items()))\n    if b'Transfer-Encoding' in headers:\n        del headers[b'Transfer-Encoding']\n    if b'Content-Length' not in headers:\n        headers[b'Content-Length'] = len(body)\n    if b'Connection' not in headers:\n        headers[b'Connection'] = b'close'\n\n    try:\n        wfile.write(b\"HTTP/1.1 %d\\r\\n\" % status)\n        for key, value in list(headers.items()):\n            send_header(wfile, key, value)\n        wfile.write(b\"\\r\\n\")\n        wfile.write(body)\n    except ssl.SSLError as e:\n        xlog.warn(\"gae send response fail. %r\", e)\n        return\n    except Exception as e:\n        if sys.version_info[0] == 3 and (\n                isinstance(e, ConnectionError) or\n                isinstance(e, ConnectionResetError) or\n                isinstance(e, BrokenPipeError)\n        ):\n            xlog.warn(\"gae send response fail. %r\", e)\n        else:\n            xlog.exception(\"send response fail %r\", e)\n\n\ndef return_fail_message(wfile):\n    html = generate_message_html(\n        '504 GAEProxy Proxy Time out', '连接超时，先休息一会再来！')\n    send_response(wfile, 504, body=utils.to_bytes(html))\n    return\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/gae_proxy/local/gae_handler.py#L191-L227","documentation":"While writing an HTTP response back to the local client browser over the (possibly TLS) socket, an ssl.SSLError occurred. The connection to the browser is abandoned; the browser will typically show a connection reset / empty response.","triggerScenarios":"send_response writing status/headers/body raises ssl.SSLError: browser closed the TLS connection early, TLS handshake/renegotiation failure, or truncation when writing body.","commonSituations":"User cancels page load, browser tab closed mid-response, MITM proxy interfering with local TLS, browser rejecting the self-signed cert mid-stream.","solutions":["Usually benign (client-side disconnect); ignore unless frequent","Check the local certificate setup (import the local CA in the browser) if it happens consistently","Disable interfering middleboxes/AV TLS scanning for localhost connections","Reproduce with curl -k against the local proxy port to isolate browser-specific TLS issues"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"except ssl.SSLError:\n    pass  # client-side TLS abort; nothing to recover server-side","preventionTips":["Import the proxy CA cert into the browser to avoid mid-stream TLS failures","Don't run TLS-inspecting middleboxes on loopback traffic"],"tags":["ssl","send-response","client-disconnect","gae-proxy"],"backgroundTag":"ssl-write-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}