Skip to content

Native Select.timeout() is a silent no-op whenever the plan is answered from an index or from a single bucket #6815

Closed

Description

@ruispereira

Summary

The native fluent Select API installs the caller's timeout on one iterator shape only. Of the four sources buildIterator() can return, two are not MultiIterators, so timeout() is silently dropped for every index-answered plan and for a single-bucket fromBuckets(...). Nothing else on the serial path consults select.timeoutInMs.

Where (HEAD 9c9d024db)

engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java:224-226:

if (select.timeoutInMs > 0 && iterator instanceof MultiIterator<? extends Identifiable> multiIterator)
  multiIterator.setTimeout(...);

The two sources that are not MultiIterator:

  • the index-answered plan returns iteratorFromIndexes, a MultiIndexCursor (engine/src/main/java/com/arcadedb/index/MultiIndexCursor.java:30 - implements IndexCursor)
  • a single-bucket fromBuckets(...) returns database.iterateBucket(...) -> bucket.iterator() (SelectExecutor.java:216)

grep timeoutInMs finds only Select.java, SelectExecutor.java:224, SelectParallelIterator.java and SelectCompiled.json(). Neither MultiIndexCursor nor the bucket iterator has a timeout field or a WorkGuard hook. This affects documents()/vertices()/edges(), count() and exists() alike, since all go through buildIterator().

Repro

The index case is the common one - any fromType plus an indexed WHERE leaf:

db.getSchema().createVertexType("V").createProperty("id", Type.INTEGER)
    .createIndex(Schema.INDEX_TYPE.LSM_TREE, true);
db.transaction(() -> { for (int i = 0; i < 100_000; i++) db.newVertex("V").set("id", i).save(); });

final SelectIterator<Vertex> it = db.select().fromType("V")
    .where().property("id").ge().value(0)          // -> range() cursor -> MultiIndexCursor
    .timeout(1, TimeUnit.MILLISECONDS, true).vertices();
while (it.hasNext()) { it.next(); Thread.sleep(1); }   // never throws TimeoutException

The same query with the WHERE on a non-indexed property does time out.

SelectExecutionTest.errorTimeout() (engine/src/test/java/com/arcadedb/query/select/SelectExecutionTest.java:282) documents the blind spot without catching it: its first block uses the unindexed name property (so it gets a MultiIterator and passes), and its second block (:299-303) builds an indexed id < 10 select with a timeout and then never iterates it, so it asserts nothing.

Suggested fix

Enforce the deadline in the consumer rather than in one source type: capture the deadline in SelectIterator/SelectExecutor and check it in SelectIterator.fetchNext() and in the executeCount()/executeExists() loops. SelectParallelIterator already does exactly this via it.checkForTimeout(). Keep the MultiIterator.setTimeout() call as the fast path.

Scope / confidence

High. This is about the native fluent Select's own timeout(), not the SQL-side arcadedb.command.timeout covered by #6266/#6465.

Activity

  1. ruispereira commented on Aug 27, 2026

    @ruispereira
    ContributorAuthor

    Companion finding on the same feature: #6816 - MultiIterator.hasNextInternal() throws unconditionally, so even on the paths where the timeout is installed, Select.timeout(v, unit, false) (the non-throwing mode) cannot truncate. The two together are why the fluent timeout() is effectively unusable today.

  2. added this to the 26.9.1 milestone on Aug 27, 2026
  3. self-assigned this
    on Aug 28, 2026
  4. robfrank commented on Aug 28, 2026

    @robfrank
    Collaborator

    Fixed in #6872.

    The timeout was being handed to the source iterator, and only one of the four kinds of source the planner can pick knew what to do with it. An index-answered query and a single-bucket fromBuckets(...) both got a source that had nowhere to store a deadline, so timeout() quietly did nothing for them - which covered the most common query shape of all, any fromType with an indexed WHERE.

    The deadline now belongs to the code that consumes the records rather than to the iterator that produces them, so every plan shape passes through the same check. This applies to documents()/vertices()/edges(), count() and exists() alike, and a select with no timeout() set is unaffected.

    One related gap is tracked separately in #6873: the vector k-NN path (nearestTo()) is a fifth plan shape that still ignores timeout().


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions