{"record":{"id":"0c648475961afcb0","repo":"prestodb/presto","slug":"not-supported-0c6484","errorCode":"NOT_SUPPORTED","errorMessage":"Target query is not running: ${queryId}","messagePattern":"Target query is not running: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/connector/system/KillQueryProcedure.java","lineNumber":61,"sourceCode":"    private final QueryManager queryManager;\n\n    @Inject\n    public KillQueryProcedure(QueryManager queryManager)\n    {\n        this.queryManager = requireNonNull(queryManager, \"queryManager is null\");\n    }\n\n    @UsedByGeneratedCode\n    public void killQuery(String queryId, String message)\n    {\n        QueryId query = parseQueryId(queryId);\n\n        try {\n            QueryState state = queryManager.getQueryState(query);\n\n            // check before killing to provide the proper error message (this is racy)\n            if (state.isDone()) {\n                throw new PrestoException(NOT_SUPPORTED, \"Target query is not running: \" + queryId);\n            }\n\n            queryManager.failQuery(query, createKillQueryException(message));\n\n            // verify if the query was killed (if not, we lost the race)\n            if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(queryManager.getQueryInfo(query).getErrorCode())) {\n                throw new PrestoException(NOT_SUPPORTED, \"Target query is not running: \" + queryId);\n            }\n        }\n        catch (NoSuchElementException e) {\n            throw new PrestoException(NOT_FOUND, \"Target query not found: \" + queryId);\n        }\n    }\n\n    public Procedure getProcedure()\n    {\n        return new Procedure(\n                \"runtime\",","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/connector/system/KillQueryProcedure.java#L43-L79","documentation":"The kill_query system procedure checks the target query's state before failing it. If QueryState.isDone() is already true (FINISHED, FAILED, or CANCELED), there is nothing to kill, so Presto throws NOT_SUPPORTED with 'Target query is not running: <queryId>'. This is the pre-kill guard branch; the same error can also surface after a lost race (see error 1805).","triggerScenarios":"CALL system.kill_query(query_id => '...', message => '...') where the query has already completed; also killed-before-check racy completions between the state check and the call.","commonSituations":"Operators killing a long-running query that finished while the console was open; automation scripts killing by a stale query ID; retries of a kill that already succeeded.","solutions":["Check the query state via the query manager/UI before calling kill_query; skip if done.","Fetch the fresh queryId right before killing rather than caching it in automation.","Treat this NOT_SUPPORTED error as idempotent success in scripts (the goal — query not running — is achieved)."],"exampleFix":"// before\nQueryState state = queryManager.getQueryState(query);\nif (state.isDone()) {\n    throw new PrestoException(NOT_SUPPORTED, \"Target query is not running: \" + queryId);\n}\n// after\nQueryState state = queryManager.getQueryState(query);\nif (state.isDone()) {\n    log.info(\"Query %s already finished with state %s; nothing to kill\", queryId, state);\n    return;\n}","handlingStrategy":"try-catch","validationCode":"QueryState state = queryManager.getQueryState(query);\nif (state.isDone()) { skip(); return; }","typeGuard":null,"tryCatchPattern":"try { killQuery(queryId, message); }\ncatch (PrestoException e) { if (e.getErrorCode() == StandardErrorCode.NOT_SUPPORTED.toErrorCode() && e.getMessage().contains(\"not running\")) { /* treat as success: idempotent kill */ } else throw e; }","preventionTips":["Re-read the query ID from system.runtime.queries immediately before killing","Treat 'not running' NOT_SUPPORTED kills as successful no-ops in automation","Avoid killing queries by cached IDs from dashboards"],"tags":["query-management","race-condition","procedure"],"backgroundTag":"query-already-done","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"}