{"record":{"id":"504501a4ca4386e5","repo":"prestodb/presto","slug":"error-reading-response-from-server","errorCode":null,"errorMessage":"Error reading response from server","messagePattern":"Error reading response from server","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-spark-base/src/main/java/com/facebook/presto/spark/execution/http/PrestoSparkHttpTaskClient.java","lineNumber":568,"sourceCode":"            for (String name : response.headers().names()) {\n                for (String value : response.headers().values(name)) {\n                    builder.put(OkHttpHeaderName.of(name), value);\n                }\n            }\n            return builder.build();\n        }\n\n        private static byte[] readResponseBytes(Response response)\n        {\n            try {\n                ResponseBody body = response.body();\n                if (body == null) {\n                    return new byte[] {};\n                }\n                return body.bytes();\n            }\n            catch (IOException e) {\n                throw new RuntimeException(\"Error reading response from server\", e);\n            }\n        }\n    }\n\n    private static class BytesResponse\n            implements BaseResponse<byte[]>\n    {\n        private final int statusCode;\n        private final ListMultimap<OkHttpHeaderName, String> headers;\n        private final byte[] bytes;\n\n        public BytesResponse(int statusCode, ListMultimap<OkHttpHeaderName, String> headers, byte[] bytes)\n        {\n            this.statusCode = statusCode;\n            this.headers = ImmutableListMultimap.copyOf(requireNonNull(headers, \"headers is null\"));\n            this.bytes = bytes;\n        }\n","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spark-base/src/main/java/com/facebook/presto/spark/execution/http/PrestoSparkHttpTaskClient.java#L550-L586","documentation":"PrestoSparkHttpTaskClient's response handler wraps any IOException raised while reading the HTTP response body bytes into a RuntimeException with this message. The server responded, but the client failed to read the body — typically a connection reset, premature EOF, or read timeout mid-body.","triggerScenarios":"readResponseBytes() (called via handle()) executes body.bytes() on the OkHttp response body and the underlying stream throws IOException (connection reset by peer, stream closed, timeout).","commonSituations":"Spark executors or the driver losing network connectivity mid-request; task server killed while streaming a response; HTTP read timeouts on large result batches; proxy/load-balancer closing idle connections.","solutions":["Retry the failed HTTP task request (task status/GET results are typically idempotent)","Check network stability between driver/executors and the task server; inspect for resets or packet loss","Increase OkHttp read timeout settings in the task client configuration","Verify the Spark executor/task process is not being killed or OOMed mid-response"],"exampleFix":"// client-side retry around the call\ntry {\n    byte[] body = client.handle(request);\n}\ncatch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Error reading response from server\")) {\n        // retry with backoff\n    }\n    throw e;\n}","handlingStrategy":"retry","validationCode":"// pre-check endpoint liveness before task calls\nResponse ping = httpClient.newCall(new Request.Builder().url(taskUri).build()).execute();\nif (!ping.isSuccessful()) throw new IllegalStateException(\"task server unreachable\");","typeGuard":"null","tryCatchPattern":"try {\n    return taskClient.handle(request);\n}\ncatch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Error reading response from server\")) {\n        return retryWithBackoff(() -> taskClient.handle(request), 3); // idempotent GET\n    }\n    throw e;\n}","preventionTips":["Set generous OkHttp read timeouts for large page batches","Keep connections alive between driver/executors and task servers","Suppress proxy idle-timeout drops below expected response durations","Monitor executor logs for OOM kills that abort streaming responses"],"tags":["network","http","okhttp","read-failure","spark"],"backgroundTag":"http-response-read-error","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"}