Another bug(?): "compact" or "database" nodes as variable bindings to job:execute()

Wednesday, 18 November 2026 · 3 messages · last reply 20 Nov 2026
PP
Peter Piwowarski18 Nov 2026 22:56 #

Hello,

Another issue with job:execute() and locks: there seems to be something odd with passing "compact" or "database" nodes to jobs as external variable bindings. Given a database named 'factbook' (created with etc/factbook.xml from the distribution archives, but its content doesn't really matter), the following query:

count(db:get('factbook')//country), job:execute("
 declare variable $foo external;
 $foo
", map { "foo": <bar/> update {} })

Yields a rather weird error:

[job:deadlock] Job may only read databases locked by caller (Reads: , Writes: (none)).

Removing the update {} (so that it should be a "constructed node"?) resolves the error; it also occurs with documents read by fetch:doc(), or document nodes fetched from the database - although that's a little odd. Binding "foo" to db:get('factbook', 'factbook.xml') (a single document) or db:get('factbook', 'factbook.xml')//country[27] (a single random element) raises the deadlock error, but binding it to db:get('factbook', 'factbook.xml')//country (i.e. a bunch of elements) seems to work as expected.

Binding to the context also seems fine, i.e. this query also works as expected:

count(db:get('factbook')//country), job:execute(".", map { "": <bar/> update {} })

I haven't dug too deeply yet, but the change to the error text from adding an actual database reference to the job is interesting:

count(db:get('factbook')//country), job:execute("
 declare variable $foo external;
 count(db:get('factbook')//city), $foo
", map { "foo": <bar/> update {} })

raises:

[job:deadlock] Job may only read databases locked by caller (Reads: ,factbook, Writes: (none)).

It's almost like it thinks it needs a lock on the (nonexistent, at least in my tests) database named "" (i.e. empty string)?

Thanks,

Peter

CG
Christian Grün19 Nov 2026 10:41 #

Hi Peter,

Your guess was right. Some technical background: before a job is started, all nodes in the bindings are copied to main memory, so the job can work on them independently of the caller. The lock analysis of the job then erroneously treated such a copy as a persistent database. This has been fixed with the latest snapshot.

The deadlock check was introduced in BaseX 13, to prevent the original and the asynchronous queries from waiting on each other. The behavior is more safe now, but also more pessimistic.

Hope this helps, Christian

Quoted text · Peter Piwowarski · 36 lines
Peter Piwowarski via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Mittwoch, 18. November 2026 um 22:56: > Hello, > > Another issue with job:execute() and locks: there seems to be something odd with passing "compact" or "database" nodes to jobs as external variable bindings. Given a database named 'factbook' (created with etc/factbook.xml from the distribution archives, but its content doesn't really matter), the following query: > > count(db:get('factbook')//country), job:execute(" > declare variable $foo external; > $foo > ", map { "foo": <bar/> update {} }) > > Yields a rather weird error: > > [job:deadlock] Job may only read databases locked by caller (Reads: , Writes: (none)). > > Removing the `update {}` (so that it should be a "constructed node"?) resolves the error; it also occurs with documents read by fetch:doc(), or document nodes fetched from the database - although that's a little odd. Binding "foo" to `db:get('factbook', 'factbook.xml')` (a single document) or `db:get('factbook', 'factbook.xml')//country[27]` (a single random element) raises the deadlock error, but binding it to `db:get('factbook', 'factbook.xml')//country` (i.e. a bunch of elements) seems to work as expected. > > Binding to the context also seems fine, i.e. this query also works as expected: > > count(db:get('factbook')//country), job:execute(".", map { "": <bar/> update {} }) > > I haven't dug too deeply yet, but the change to the error text from adding an actual database reference to the job is interesting: > > count(db:get('factbook')//country), job:execute(" > declare variable $foo external; > count(db:get('factbook')//city), $foo > ", map { "foo": <bar/> update {} }) > > raises: > > [job:deadlock] Job may only read databases locked by caller (Reads: ,factbook, Writes: (none)). > > It's almost like it thinks it needs a lock on the (nonexistent, at least in my tests) database named "" (i.e. empty string)? > > Thanks, > > Peter
PP
Peter Piwowarski20 Nov 2026 15:40 #
Quoted text · Christian Grün · 15 lines
Christian Grün wrote: > Hi Peter, > > Your guess was right. Some technical background: before a job is > started, all nodes in the bindings are copied to main memory, so the > job can work on them independently of the caller. The lock analysis of > the job then erroneously treated such a copy as a persistent database. > This has been fixed with the latest snapshot. > > The deadlock check was introduced in BaseX 13, to prevent the original > and the asynchronous queries from waiting on each other. The behavior > is more safe now, but also more pessimistic. > > Hope this helps, > Christian

It does, thank you very much.


⚡Generated with XQuery