{"record":{"id":"abd18c06d06fd905","repo":"prestodb/presto","slug":"expected-response-code-to-be-200-but-was-s-n-s-abd18c","errorCode":null,"errorMessage":"Expected response code to be 200, but was %s:%n%s","messagePattern":"Expected response code to be 200, but was (.+?):%n(.+?)","errorType":"exception","errorClass":"PageTransportErrorException","httpStatus":null,"severity":"error","filePath":"presto-spark-base/src/main/java/com/facebook/presto/spark/execution/http/PrestoSparkHttpTaskClient.java","lineNumber":753,"sourceCode":"                        ResponseBody responseBody = response.body();\n                        if (responseBody != null) {\n                            try (BufferedReader reader = new BufferedReader(new InputStreamReader(responseBody.byteStream(), UTF_8))) {\n                                // Get up to 1000 lines for debugging\n                                for (int i = 0; i < 1000; i++) {\n                                    String line = reader.readLine();\n                                    // Don't output more than 100KB\n                                    if (line == null || body.length() + line.length() > 100 * 1024) {\n                                        break;\n                                    }\n                                    body.append(line + \"\\n\");\n                                }\n                            }\n                        }\n                    }\n                    catch (RuntimeException | IOException e) {\n                        // Ignored. Just return whatever message we were able to decode\n                    }\n                    throw new PageTransportErrorException(\n                            HostAddress.fromUri(request.url().uri()),\n                            format(\"Expected response code to be 200, but was %s:%n%s\",\n                                    response.code(),\n                                    body.toString()));\n                }\n\n                // invalid content type can happen when an error page is returned, but is unlikely given the above 200\n                String contentType = response.header(CONTENT_TYPE);\n                if (contentType == null) {\n                    throw new PageTransportErrorException(\n                            HostAddress.fromUri(request.url().uri()),\n                            format(\"%s header is not set: %s\", CONTENT_TYPE, response));\n                }\n                if (!mediaTypeMatches(contentType, PRESTO_PAGES_TYPE)) {\n                    throw new PageTransportErrorException(\n                            HostAddress.fromUri(request.url().uri()),\n                            format(\"Expected %s response from server but got %s\", PRESTO_PAGES_TYPE, contentType));\n                }","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spark-base/src/main/java/com/facebook/presto/spark/execution/http/PrestoSparkHttpTaskClient.java#L735-L771","documentation":"The HTTP task client expects a 200 OK from the Spark task server; any other status raises PageTransportErrorException with the actual response code and body. The body text is decoded best-effort (exceptions while decoding are ignored) to help diagnose the server-side failure.","triggerScenarios":"Any PrestoSparkHttpTaskClient.handle() call where response.code() != 200 — e.g. task server returns 404 (task not found/already cleaned), 500 (task failure), 503 (overloaded), or an auth/gateway error page.","commonSituations":"Spark task retries/executors lost causing 404s for stale task locations; task server crashes returning 500; reverse proxy returning error pages; query results requested after task cleanup.","solutions":["Read the embedded status code and response body to identify the server-side cause","Retry against the correct/current task location — 404 often means the executor was replaced after a retry","Inspect Spark executor logs for the 500's root cause","Check for proxies/interceptors intercepting the request and returning error pages"],"exampleFix":"// handle 404 after task retry by refreshing task info\ntry {\n    return taskClient.handle(request);\n}\ncatch (PageTransportErrorException e) {\n    if (e.getMessage().contains(\"Expected response code to be 200, but was 404\")) {\n        // refetch SqlTask location/status and rebuild the request\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// verify task location is current before calling\nTaskInfo info = taskClient.getTaskInfo(taskId);\nif (info.getTaskStatus().getState().isDone()) {\n    throw new IllegalStateException(\"task already finished; refetch location\");\n}","typeGuard":"null","tryCatchPattern":"try {\n    return taskClient.handle(request);\n}\ncatch (PageTransportErrorException e) {\n    String msg = e.getMessage();\n    if (msg.contains(\"but was 404\")) { /* stale task: refetch task status/location */ }\n    else if (msg.contains(\"but was 500\")) { /* server-side task failure: read body for cause */ }\n    else if (msg.contains(\"but was 503\")) { /* overloaded: retry with backoff */ }\n    throw e;\n}","preventionTips":["Refresh task locations after executor loss/retry before re-issuing requests","Parse the response body embedded in the error for the real server-side cause","Add backoff retries only for 503-class responses","Monitor Spark executor failures correlated with client 4xx/5xx spikes"],"tags":["http","http-status","page-transport","spark","network"],"backgroundTag":"unexpected-http-status","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"}