{"record":{"id":"fde62b53bb7ff4a1","repo":"prestodb/presto","slug":"query-not-found","errorCode":null,"errorMessage":"Query not found","messagePattern":"Query not found","errorType":"http","errorClass":"WebApplicationException","httpStatus":404,"severity":"warning","filePath":"presto-main/src/main/java/com/facebook/presto/server/protocol/LocalQueryProvider.java","lineNumber":196,"sourceCode":"            }\n            query.cancel();\n        }\n\n        // cancel the query execution directly instead of creating the statement client\n        try {\n            if (!queryManager.isQuerySlugValid(queryId, slug)) {\n                throw notFound(\"Query not found\");\n            }\n            queryManager.cancelQuery(queryId);\n        }\n        catch (NoSuchElementException e) {\n            throw notFound(\"Query not found\");\n        }\n    }\n\n    private static WebApplicationException notFound(String message)\n    {\n        throw new WebApplicationException(\n                Response.status(Status.NOT_FOUND)\n                        .type(TEXT_PLAIN_TYPE)\n                        .entity(message)\n                        .build());\n    }\n}\n","sourceCodeStart":178,"sourceCodeEnd":203,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main/src/main/java/com/facebook/presto/server/protocol/LocalQueryProvider.java#L178-L203","documentation":"NimbusOAuth2Client.getTokenResponse wraps failures from the token endpoint exchange (authorization-code or refresh-token grant) as a ChallengeFailedException with the token endpoint's error details appended; authentication cannot proceed without a valid access token.","triggerScenarios":"Calling getQueryInfo or cancelQuery on the embedded/local dispatcher for a queryId that was never submitted to this instance, already completed and purged, or after restarting the embedded Presto server process.","commonSituations":"Testing with LocalQueryProvider/embedded server and reusing query IDs across restarts, cancel racing with query completion, clients keeping references to finished queries.","solutions":["Fetch/hold the queryId from the same LocalQueryProvider submission call before querying or cancelling","Handle 404 as terminal state (query already finished) and skip cancel","Avoid restarting the embedded server between submit and fetch/cancel","Use the dispatcher's completion future to learn query state instead of polling getQuery after completion"],"exampleFix":"// before\nqueryProvider.cancelQuery(queryId); // throws if already finished\n// after\ntry { queryProvider.cancelQuery(queryId); } catch (WebApplicationException e) { if (e.getResponse().getStatus() == 404) return; throw e; }","handlingStrategy":"try-catch","validationCode":"// Only use queryIds returned by the same LocalQueryProvider submission in this process lifetime","typeGuard":"boolean isLiveLocalQuery(LocalQueryProvider provider, QueryId id) { try { provider.getQueryInfo(id); return true; } catch (WebApplicationException e) { return e.getResponse().getStatus() != 404; } }","tryCatchPattern":"try { provider.cancelQuery(queryId); } catch (WebApplicationException e) { if (e.getResponse().getStatus() == 404) { /* already gone */ } else throw e; }","preventionTips":["Use submission-time futures/completion handles instead of polling getQuery after completion","Do not persist queryIds across embedded-server restarts","Cancel promptly; the window between completion and cancel can 404"],"tags":["http-404","embedded","query-lifecycle"],"backgroundTag":"resource-not-found","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"}