#7547·surrealdb

Bug: `TIMEOUT $param` on a SELECT inside a closure is silently ignored (the parameter reads as NONE)

Author: omer9564Created Sep 28, 2026Updated Sep 29, 2026

What component does this affect?

SurrealDB Server

Describe the bug

A SELECT's TIMEOUT clause may reference a parameter. At top level this works: TIMEOUT $to with $to = 1ms expires, and an unbound $nope is rejected with Invalid timeout value.

When the same SELECT sits inside a closure body (array.map(|$i| …), .filter(…), array::map(arr, |$i| …)), the parameter in the TIMEOUT clause evaluates to NONE, and a NONE timeout is then treated as no timeout. The subquery runs to completion and returns its full result. The query succeeds with no error or warning, even with a 1 ms budget.

Only the TIMEOUT clause is affected:

  • the same parameter is readable in the closure body;
  • other parameters are readable in the same subquery's WHERE;
  • a literal duration in the TIMEOUT works;
  • a closure argument used as the TIMEOUT works.

Reproduced three ways:

  • the official surrealdb/surrealdb:v3.2.4 image, start --user root --pass root memory, over HTTP /sql;
  • the Rust SDK surrealdb = "3.2.4", with the parameter bound through .bind(), over ws://;
  • the same SDK against the embedded mem:// and rocksdb:// engines.

Steps to reproduce

sql
DEFINE NAMESPACE IF NOT EXISTS repro; USE NS repro;
DEFINE DATABASE IF NOT EXISTS repro; USE DB repro;
DEFINE TABLE IF NOT EXISTS t SCHEMALESS;
CREATE |t:300000| CONTENT { n: 1 } RETURN NONE;

Each case below is a separate request. Timings are from the in-memory server on one machine, and only their order of magnitude matters.

# Query Observed Expected
1 LET $to = 1ms; SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT $to; ERR "The query was not executed because it exceeded the timeout: 1ms" (29 ms) same
2 SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT $nope; ERR "Invalid timeout value" same
3 LET $to = 1ms; RETURN [1, 2].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT $to))); OK [300000, 300000] after 1.9 s ERR timeout, as in #1
4 RETURN [1, 2].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT $nope))); OK [300000, 300000] after 1.9 s ERR "Invalid timeout value", as in #2
5 RETURN [1, 2].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT 1ms))); ERR timeout (33 ms) same
6 LET $to = 1ms; RETURN [1, 2].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT <duration>$to))); ERR "Could not cast into duration using input NONE" ERR timeout. This case shows $to reads as NONE in that position.
7 LET $to = 1ms; RETURN [1].map(|$i| $to); OK [1ms] same (the parameter IS visible in the closure body)
8 LET $min = 0; RETURN [1].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= $min LIMIT 5))); OK [5] same (parameters ARE visible in the subquery's WHERE)
9 LET $to = 1ms; RETURN [$to, $to].map(|$d| array::len((SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT $d))); ERR timeout same (a closure argument works)
10 LET $to = 1ms; SELECT VALUE [1, 2].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= 0))) FROM ONLY {} TIMEOUT $to; ERR timeout same (an outer statement TIMEOUT bounds the closure)

.filter(|$i| …) and the function form array::map([1, 2], |$i| …) behave like #3.

Binding the parameter through the Rust SDK instead of LET gives the same result:

rust
db.query("RETURN [1,2].map(|$i| array::len((SELECT VALUE id FROM t WHERE n >= 0 TIMEOUT $to)));")
  .bind(("to", surrealdb::types::Duration::from(std::time::Duration::from_millis(1))))
  .await?
  .check()?; // Ok, full result, ~3 s. Without the closure: Err(Query(Some(TimedOut { duration: 1ms })))

Why it matters

A TIMEOUT is often a safety bound: a query that must fail rather than run long. Inside a closure, a parameterised bound silently disappears. There's no error, and the result is a normal successful response, so a caller cannot tell that the bound was not applied.

Cases #2 and #4 are the clearest contrast. The same invalid (unbound) timeout is rejected at top level and silently accepted inside a closure.

Workarounds

  • Put the TIMEOUT on the outermost statement (#10).
  • Or pass the duration into the closure as an argument (#9).
  • Or use a literal (#5).

Expected behaviour

The TIMEOUT expression of a SELECT inside a closure resolves parameters the way the rest of that SELECT does (#8) and the way a top-level SELECT does (#1). A NONE or non-duration value is rejected with Invalid timeout value in every position.

SurrealDB version

3.2.4 (the official surrealdb/surrealdb:v3.2.4 image, and the Rust SDK surrealdb = "3.2.4" with the embedded mem:// and rocksdb:// engines). Not yet tried on 3.3.0-beta.

Contact Details

No response

Could this be a bug with your application?

  • I confirm this is a bug with SurrealDB, not with my own application

Is there an existing issue for this?

  • I confirm that I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct