{"record":{"id":"71684c6631ddc3e3","repo":"prestodb/presto","slug":"request-to-remote-presto-server-failed","errorCode":null,"errorMessage":"Request to remote Presto server failed","messagePattern":"Request to remote Presto server failed","errorType":"exception","errorClass":"ProxyException","httpStatus":502,"severity":"error","filePath":"presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java","lineNumber":42,"sourceCode":"import java.io.IOException;\n\nimport static com.facebook.airlift.http.client.HttpStatus.NO_CONTENT;\nimport static com.facebook.airlift.http.client.HttpStatus.OK;\nimport static com.google.common.io.ByteStreams.toByteArray;\nimport static com.google.common.net.HttpHeaders.CONTENT_TYPE;\nimport static java.lang.String.format;\nimport static java.nio.charset.StandardCharsets.US_ASCII;\nimport static java.util.Objects.requireNonNull;\n\npublic class ProxyResponseHandler\n        implements ResponseHandler<ProxyResponse, RuntimeException>\n{\n    private static final MediaType MEDIA_TYPE_JSON = MediaType.create(\"application\", \"json\");\n\n    @Override\n    public ProxyResponse handleException(Request request, Exception exception)\n    {\n        throw new ProxyException(\"Request to remote Presto server failed\", exception);\n    }\n\n    @Override\n    public ProxyResponse handle(Request request, Response response)\n    {\n        if (response.getStatusCode() == NO_CONTENT.code()) {\n            return new ProxyResponse(response.getHeaders(), new byte[0]);\n        }\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)) {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java#L24-L60","documentation":"ProxyResponseHandler.handleException is the generic failure path for any Exception raised while executing the request against the remote Presto server. It wraps the cause in a ProxyException with the fixed message 'Request to remote Presto server failed'. It signals a transport-level failure, not an HTTP error status.","triggerScenarios":"Any IOException/connection failure thrown by the HTTP client while calling the remote server (connect timeout, read timeout, connection reset, TLS failure) during a proxied statement/request.","commonSituations":"Remote coordinator overloaded or restarted mid-request; idle connection reaped by a firewall causing reset; DNS failure; misconfigured remote server URI.","solutions":["Read the wrapped cause (getCause()) for the real transport error.","Verify the remote Presto server URI, DNS, and network reachability.","Increase client connect/read timeouts if failures correlate with long queries.","Retry with backoff; enable HTTP client connection keep-alive/pool hygiene."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight connectivity to the remote server\nconst net = require('net');\nconst s = net.connect(port, host);\ns.on('connect', () => { console.log('reachable'); s.end(); });\ns.on('error', e => console.error('unreachable:', e.message));","typeGuard":null,"tryCatchPattern":"try {\n  return await proxyClient.execute(req);\n} catch (e) {\n  if (e instanceof ProxyException && e.getCause() instanceof java.io.IOException) {\n    return retryWithBackoff(req, 3); // transient transport failure\n  }\n  throw e;\n}","preventionTips":["Configure connect/read timeouts explicitly on the HTTP client","Enable keep-alive and validate stale connections before reuse","Monitor remote server health and take it out of rotation when unhealthy","Log e.getCause() to distinguish DNS vs connect vs read failures"],"tags":["network","http","proxy","connection"],"backgroundTag":"connection-refused","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"}