prestodb/presto · error · WebApplicationException

${e.getMessage()}

Error message

${e.getMessage()}

What it means

badRequest wraps any message into an HTTP response (here BAD_GATEWAY 502) thrown as a WebApplicationException from the Presto proxy resource. The proxy re-throws an upstream failure's getMessage() verbatim as a plain-text response body. It indicates the proxy's request to the backend Presto server failed.

Source

Thrown at presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResource.java:286

    private void setupXForwardedFor(HttpServletRequest servletRequest, Request.Builder requestBuilder)
    {
        StringBuilder xForwardedFor = new StringBuilder();
        if (servletRequest.getHeader(X_FORWARDED_FOR) != null) {
            xForwardedFor.append(servletRequest.getHeader(X_FORWARDED_FOR) + ",");
        }
        xForwardedFor.append(servletRequest.getRemoteAddr());
        requestBuilder.addHeader(X_FORWARDED_FOR, xForwardedFor.toString());
    }

    private static <T> T handleProxyException(Request request, ProxyException e)
    {
        log.warn(e, "Proxy request failed: %s %s", request.getMethod(), request.getUri());
        throw badRequest(BAD_GATEWAY, e.getMessage());
    }

    private static WebApplicationException badRequest(Status status, String message)
    {
        throw new WebApplicationException(
                Response.status(status)
                        .type(TEXT_PLAIN_TYPE)
                        .entity(message)
                        .build());
    }

    private static boolean isPrestoHeader(String name)
    {
        return name.toLowerCase(ENGLISH).startsWith("x-presto-");
    }

    private static Response responseWithHeaders(ResponseBuilder builder, ProxyResponse response)
    {
        response.getHeaders().forEach((headerName, value) -> {
            String name = headerName.toString();
            if (isPrestoHeader(name) || name.equalsIgnoreCase(SET_COOKIE)) {
                builder.header(name, value);
            }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check that the upstream Presto coordinator address the proxy forwards to is reachable (curl it directly).
  2. Inspect the proxy logs for the underlying 'Proxy request failed' warning with the full stack trace.
  3. Verify network/DNS/firewall and any proxy-to-backend authentication configuration.
  4. Retry the query; if persistent, fix backend health or connection pooling/timeouts.

Example fix

// before: raw message leaks internals
catch (Exception e) { throw badRequest(BAD_GATEWAY, e.getMessage()); }
// after: log full cause, return sanitized body
log.warn(e, "Proxy request failed"); throw badRequest(BAD_GATEWAY, "Upstream Presto server unavailable");
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling the proxy, check backend health
const res = await fetch(backendUri + "/v1/info");
if (!res.ok) throw new Error("Presto coordinator unavailable: " + res.status);

Try / catch

try {
  const out = await proxyFetch(uri, opts);
} catch (e) {
  if (e.status === 502) {
    // inspect e.message (upstream cause); retry or surface backend-down
    log.warn("Upstream Presto failed:", e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: handleProxyException catches a failure while forwarding the HTTP request to the remote Presto server (getNext, cancelQuery, or bearer-token setup failed) and calls badRequest(BAD_GATEWAY, e.getMessage()).

Common situations: Backend Presto coordinator down or restarting; network/timeout between proxy and coordinator; TLS or auth (bearer token) handshake failure; backend returning garbage connection errors.

Related errors


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