{"record":{"id":"df6349956af3ba9e","repo":"prestodb/presto","slug":"failed-reading-response-from-remote-presto-server","errorCode":null,"errorMessage":"Failed reading response from remote Presto server","messagePattern":"Failed reading response from remote Presto server","errorType":"exception","errorClass":"ProxyException","httpStatus":502,"severity":"error","filePath":"presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java","lineNumber":68,"sourceCode":"        }\n\n        if (response.getStatusCode() != OK.code()) {\n            throw new ProxyException(format(\"Bad status code from remote Presto server: %s: %s\", response.getStatusCode(), readBody(response)));\n        }\n\n        String contentType = response.getHeader(CONTENT_TYPE);\n        if (contentType == null) {\n            throw new ProxyException(\"No Content-Type set in response from remote Presto server\");\n        }\n        if (!MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) {\n            throw new ProxyException(\"Bad Content-Type from remote Presto server:\" + contentType);\n        }\n\n        try {\n            return new ProxyResponse(response.getHeaders(), toByteArray(response.getInputStream()));\n        }\n        catch (IOException e) {\n            throw new ProxyException(\"Failed reading response from remote Presto server\", e);\n        }\n    }\n\n    private static String readBody(Response response)\n    {\n        try {\n            return new String(toByteArray(response.getInputStream()), US_ASCII);\n        }\n        catch (IOException e) {\n            return \"\";\n        }\n    }\n\n    public static class ProxyResponse\n    {\n        private final ListMultimap<HeaderName, String> headers;\n        private final byte[] body;\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java#L50-L86","documentation":"The response passed status and Content-Type checks, but reading its body stream into bytes threw IOException. The proxy wraps this in a ProxyException with 'Failed reading response from remote Presto server'. This is a mid-body transport failure, not a parse error.","triggerScenarios":"Connection reset or timeout while streaming the response body; server closed the connection prematurely; client-side stream/disk issues while buffering the body.","commonSituations":"Large result sets hitting read timeouts; backend OOM-killed mid-response; flaky network or LB idle-timeout smaller than body transfer time.","solutions":["Check the wrapped IOException cause for 'reset'/'timeout' specifics.","Increase HTTP client read timeouts and any intermediary idle timeouts.","Retry the request; for large results reduce page size or use spooling.","Check backend server logs for errors at the time of the failure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// estimate body transfer time and ensure timeouts exceed it\nconst head = await fetch(backendUri + path, { method: \"HEAD\" });\nconst bytes = Number(head.headers.get(\"content-length\") || 0);\nif (bytes / minBytesPerSecond > readTimeoutSeconds) console.warn(\"read timeout too small for body size\", bytes);","typeGuard":null,"tryCatchPattern":"try {\n  return await proxyCall(req);\n} catch (e) {\n  if (String(e.message).includes(\"Failed reading response\")) {\n    return retryWithBackoff(req, 3); // transient stream failure\n  }\n  throw e;\n}","preventionTips":["Set read timeouts generously above worst-case body transfer time","Align LB/proxy idle timeouts with client read timeouts","Split very large result requests into smaller pages","Watch backend logs for OOM/crashes correlating with failures"],"tags":["network","io","http","stream"],"backgroundTag":"connection-reset-during-read","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}