Skip to content

[BUG] PIT is not deleted when a Calcite query is rejected for memory at start #5860

Open

Description

@RyanL1997

Issue Summary:

When a query is rejected with Insufficient resources to start query, the PIT it already created is never deleted. It stays open until plugins.sql.cursor.keep_alive (1m) expires.

In CalciteEnumerableIndexScan.enumerator(), osIndex.buildRequest(...) is passed as a constructor argument, so it runs first and creates the PIT. The OpenSearchIndexEnumerator constructor then fails its memory check and throws, so no enumerator exists and close() never runs to delete the PIT.

Steps to Reproduce:

  1. Index 200k docs into a 2-shard index.
  2. Bring heap above plugins.query.memory_limit (default 85%).
  3. Run a full-scan query 20 times, e.g. source=big | eval z=concat(s, cast(k as string)) | eventstats count() as c by g | sort - z | head 5.
  4. Check point_in_time_current in _nodes/stats/indices/search.

###Expected Result:
no open PIT contexts after the queries fail.

Actual Result:

every "start query" rejection leaves 2 open PIT contexts (one per shard) until they expire. Queries rejected mid-scan ("continue processing") don't leak, and neither do successful ones.

Impact:

under memory pressure, rejected queries pile up open PIT contexts toward search.max_open_pit_context (300). New queries can keep failing for up to a minute after memory recovers. Async submits make this easier to hit.

Suggested fix:

check the resource monitor before calling buildRequest, or delete the PIT if the constructor throws.

Env Setup - OpenSearch Version:

3.10.0-SNAPSHOT, main @ 866dafcbd

Activity

  1. added
    bug
    PPL
    on Oct 9, 2026
  2. cc-bb-aa commented on Oct 10, 2026

    @cc-bb-aa

    A rejected query leaking its PIT turns backpressure into slow resource exhaustion. Deleting the PIT in the rejection path, or tying PIT lifetime to the request that created it, closes the leak. A test that rejects queries in a loop and asserts the open PIT count stays flat would lock in the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions