{"record":{"id":"d1e450d27c42c683","repo":"apache/seatunnel","slug":"attempted-to-clear-scroll-with-empty-scroll-id","errorCode":null,"errorMessage":"Attempted to clear scroll with empty scroll ID","messagePattern":"Attempted to clear scroll with empty scroll ID","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/client/EsRestClient.java","lineNumber":312,"sourceCode":"        return getDocsFromScrollRequest(\"/_search/scroll\", JsonUtils.toJsonString(param));\n    }\n\n    public ScrollResult searchWithSql(String scrollId, JsonNode columnNodes) {\n        Map<String, String> param = new HashMap<>();\n        param.put(\"cursor\", scrollId);\n        String endpoint = \"/_sql?format=json\";\n        return getDocsFromSqlResult(endpoint, JsonUtils.toJsonString(param), columnNodes);\n    }\n\n    /**\n     * Clear scroll context to release server-side resources.\n     *\n     * @param scrollId The scroll ID to clear\n     * @return True if the scroll was successfully cleared\n     */\n    public boolean clearScroll(String scrollId) {\n        if (StringUtils.isEmpty(scrollId)) {\n            log.warn(\"Attempted to clear scroll with empty scroll ID\");\n            return false;\n        }\n\n        String endpoint = \"/_search/scroll\";\n        Request request = new Request(\"DELETE\", endpoint);\n        Map<String, String> requestBody = new HashMap<>();\n        requestBody.put(\"scroll_id\", scrollId);\n        request.setJsonEntity(JsonUtils.toJsonString(requestBody));\n\n        try {\n            Response response = restClient.performRequest(request);\n            if (response == null) {\n                log.warn(\"DELETE {} response null for scroll ID: {}\", endpoint, scrollId);\n                return false;\n            }\n            String entity = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);\n            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {\n                JsonNode jsonNode = JsonUtils.parseObject(entity);","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/client/EsRestClient.java#L294-L330","documentation":"Guard in EsRestClient.clearScroll: called with a null or empty scrollId, so the client logs a warning and returns false without issuing any DELETE to Elasticsearch. Clearing a scroll with no ID is meaningless — the method short-circuits to avoid a pointless HTTP round trip. The scroll simply remains uncleared (a resource leak if the ID was lost).","triggerScenarios":"clearScroll(scrollId) invoked with null or \"\" — typically the scroll ID was never captured from a search response, or the search that created it never ran/failed before returning an ID.","commonSituations":"Search path returned no scroll ID on an empty or failed initial search but cleanup still runs in finally; code path that clears scrolls on close even when scrolling was disabled; refactoring changed how the ID is passed and it is now dropped.","solutions":["Capture the scroll ID from the initial search response before any code path can lose it","Skip clearScroll when no ID exists instead of treating false as an error: if (scrollId != null) client.clearScroll(scrollId)","Trace why the ID was empty — check whether the initial search actually used scroll and succeeded","On close paths, only clear scrolls that were actually opened (track them in a set)"],"exampleFix":"// before\nboolean cleared = esClient.clearScroll(scrollId);\n// after\nif (scrollId != null && !scrollId.isEmpty()) {\n    boolean cleared = esClient.clearScroll(scrollId);\n}","handlingStrategy":"validation","validationCode":"boolean shouldClear = scrollId != null && !scrollId.isEmpty();","typeGuard":"boolean hasScrollId(String id) { return id != null && !id.isEmpty(); }","tryCatchPattern":null,"preventionTips":["Capture scroll IDs at the point the scroll search succeeds","Only register cleanup for scrolls actually opened","Treat clearScroll==false without an ID as a no-op, not an error","Null-check before close-time cleanup loops"],"tags":["elasticsearch","scroll","empty-id","guard"],"backgroundTag":"empty-required-field","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}