{"record":{"id":"036d8de08c48a2f6","repo":"prestodb/presto","slug":"generic-internal-error-036d8d","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"TaskResultFetcher is closed with %s pages left in the buffer","messagePattern":"TaskResultFetcher is closed with (.+?) pages left in the buffer","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-spark-base/src/main/java/com/facebook/presto/spark/execution/nativeprocess/HttpNativeExecutionTaskResultFetcher.java","lineNumber":104,"sourceCode":"        this.taskHasResult = requireNonNull(taskHasResult, \"taskHasResult is null\");\n    }\n\n    public void start()\n    {\n        scheduledFuture = scheduler.scheduleAtFixedRate(this::doGetResults,\n                0,\n                (long) FETCH_INTERVAL.getValue(),\n                FETCH_INTERVAL.getUnit());\n    }\n\n    public void stop(boolean success)\n    {\n        if (scheduledFuture != null) {\n            scheduledFuture.cancel(false);\n        }\n\n        if (success && !pageBuffer.isEmpty()) {\n            throw new PrestoException(GENERIC_INTERNAL_ERROR, format(\"TaskResultFetcher is closed with %s pages left in the buffer\", pageBuffer.size()));\n        }\n    }\n\n    /**\n     * Blocking call to poll from result buffer. Blocks until content becomes\n     * available in the buffer, or until timeout is hit.\n     *\n     * @return the first {@link SerializedPage} result buffer contains.\n     */\n    public Optional<SerializedPage> pollPage()\n            throws InterruptedException\n    {\n        throwIfFailed();\n        SerializedPage page = pageBuffer.poll((long) POLL_TIMEOUT.getValue(), POLL_TIMEOUT.getUnit());\n        if (page != null) {\n            bufferMemoryBytes.addAndGet(-page.getSizeInBytes());\n            return Optional.of(page);\n        }","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spark-base/src/main/java/com/facebook/presto/spark/execution/nativeprocess/HttpNativeExecutionTaskResultFetcher.java#L86-L122","documentation":"HttpNativeExecutionTaskResultFetcher buffers serialized pages fetched from native workers. On stop(), if all fetches succeeded (success == true) but the pageBuffer still contains un-consumed pages, Presto throws GENERIC_INTERNAL_ERROR because silently discarding successfully fetched result pages would lose query output data.","triggerScenarios":"stop() is called while pageBuffer is non-empty and success is true — i.e., the caller finished/cancelled polling (e.g., abandoned getNextPage polling after task completion) without draining all buffered pages from the native worker.","commonSituations":"Query cancellation or early termination of result consumption after the native task already wrote all pages; upstream logic that stops polling once a limit is reached without draining the buffer; a bug causing getNextPage to not be called for all buffered output.","solutions":["Consume all pages via getNextPage/poll until the buffer is empty before calling stop()","If intentionally abandoning results, use the failure/cancel path (success=false) rather than a successful stop with data remaining","Check for early-exit logic (limit/partial consumption) that skips buffered pages and drain the fetcher explicitly"],"exampleFix":"// before\nresultFetcher.stop(); // throws if pages remain\n// after\nwhile (!resultFetcher.isBufferEmpty()) {\n    resultFetcher.getNextPage(NEXT_PAGE_TOKEN, Duration.ofSeconds(30));\n}\nresultFetcher.stop();","handlingStrategy":"validation","validationCode":"// before stop()\nif (resultFetcher.hasBufferedPages()) {\n    // drain or explicitly acknowledge discarding results\n}","typeGuard":null,"tryCatchPattern":"try {\n    resultFetcher.stop();\n} catch (PrestoException e) {\n    // pages were fetched but never consumed; log lost-output diagnostics\n}","preventionTips":["Always drain the result fetcher before stopping it","Use the cancel/failure path when abandoning results early","Track consumption completion (e.g., no-more-output flag) before lifecycle close"],"tags":["native-execution","page-buffer","resource-lifecycle"],"backgroundTag":"undrained-result-buffer","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"}