prestodb/presto · error · RuntimeException

Error reading response from server

Error message

Error reading response from server

What it means

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.

Source

Thrown at presto-spark-base/src/main/java/com/facebook/presto/spark/execution/http/PrestoSparkHttpTaskClient.java:568

            for (String name : response.headers().names()) {
                for (String value : response.headers().values(name)) {
                    builder.put(OkHttpHeaderName.of(name), value);
                }
            }
            return builder.build();
        }

        private static byte[] readResponseBytes(Response response)
        {
            try {
                ResponseBody body = response.body();
                if (body == null) {
                    return new byte[] {};
                }
                return body.bytes();
            }
            catch (IOException e) {
                throw new RuntimeException("Error reading response from server", e);
            }
        }
    }

    private static class BytesResponse
            implements BaseResponse<byte[]>
    {
        private final int statusCode;
        private final ListMultimap<OkHttpHeaderName, String> headers;
        private final byte[] bytes;

        public BytesResponse(int statusCode, ListMultimap<OkHttpHeaderName, String> headers, byte[] bytes)
        {
            this.statusCode = statusCode;
            this.headers = ImmutableListMultimap.copyOf(requireNonNull(headers, "headers is null"));
            this.bytes = bytes;
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Retry the failed HTTP task request (task status/GET results are typically idempotent)
  2. Check network stability between driver/executors and the task server; inspect for resets or packet loss
  3. Increase OkHttp read timeout settings in the task client configuration
  4. Verify the Spark executor/task process is not being killed or OOMed mid-response

Example fix

// client-side retry around the call
try {
    byte[] body = client.handle(request);
}
catch (RuntimeException e) {
    if (e.getMessage().startsWith("Error reading response from server")) {
        // retry with backoff
    }
    throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

// pre-check endpoint liveness before task calls
Response ping = httpClient.newCall(new Request.Builder().url(taskUri).build()).execute();
if (!ping.isSuccessful()) throw new IllegalStateException("task server unreachable");

Type guard

null

Try / catch

try {
    return taskClient.handle(request);
}
catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains("Error reading response from server")) {
        return retryWithBackoff(() -> taskClient.handle(request), 3); // idempotent GET
    }
    throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/504501a4ca4386e5. Report an issue: GitHub.