[Bug] REST server-side scan planning retains fetched FileScanTasks indefinitely
Apache Iceberg version
1.10.1
Query engine
Starrocks
Please describe the bug 🐞
Query engine
REST Catalog server-side scan planning.
Please describe the bug
The reference implementation of REST server-side scan planning keeps all planned
FileScanTask objects in the singleton InMemoryPlanningState, even after clients
have successfully fetched every plan task.
As a result, repeated successful scans cause retained heap usage to grow approximately linearly with the number of planned files.
The retained state is stored in the following maps:
Map<String, List
The normal successful fetch path only reads these maps:
`List
return FetchScanTasksResponse.builder() .withFileScanTasks(fileScanTasks) .withPlanTasks(IN_MEMORY_PLANNING_STATE.nextPlanTask(planTask)) .withSpecsById(table.specs()) .build();`
Neither fileScanTasksForPlanTask nor nextPlanTask removes the fetched entries. The initial task returned by synchronous planTableScan or asynchronous fetchPlanningResult is also retained. Currently, the state is released only when cancelPlanning calls InMemoryPlanningState.cancelPlan. However, according to the REST Catalog OpenAPI specification, cancellation is not required after scan tasks have been fetched for every plan task. This implies that a successful fetch lifecycle must eventually release fetched task state without requiring an explicit cancellation request. Specification: https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml Relevant implementation: https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/rest/InMemoryPlanningState.java Impact In a long-running REST catalog deployment based on this implementation, we observed:
-
Heap usage continuously increasing after successful scans
-
Tens of millions of retained FileScanTask objects
-
More than 20 GB of heap retained by planning state
-
Full GC unable to reclaim the objects
-
No active scans corresponding to most retained tasks
-
No cancellation requests because all plan tasks had already been fetched successfully
In one observation window, approximately 25 million FileScanTask objects were retained after about 22 hours of operation. This may eventually cause excessive GC pressure or an OutOfMemoryError.
Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
Confirmed against current main — this is a real leak on the spec-conformant happy path, not just a cache without eviction.
InMemoryPlanningState.fileScanTasksForPlanTask (line 112) and nextPlanTask (line 121) are plain
get calls. The only removals are in cancelPlan (lines 165-166) and the full clear(), and the
class is a process-lifetime singleton, so every successful scan adds state that is never reclaimed.
What makes it a defect rather than a design choice is the spec. rest-catalog-open-api.yaml states
that cancellation "is not necessary after fetchScanTasks has been used to fetch scan tasks for each
plan task". A client that behaves exactly as specified therefore never calls cancelPlanning, so the
only code path that frees state is the one such a client never takes.
There is already a complete fix in #17429 by @Solaris-star, which adds releasePlanTask and
releaseAsyncPlanForTask and calls them from fetchScanTasks, with tests. It was closed by its
own author on 2026-08-12 after two weeks with no review — not rejected on merit. I have commented
there with the two points a reviewer would want covered (that fetch becomes non-idempotent, which is
spec-defensible but should be stated; and that deriving the planId by counting hyphens in the key is
fragile).
I have not opened a competing PR. The efficient path here is for a committer to look at #17429.