Skip to content

db-worker-node logs the full DataScript DB for query input errors, producing multi-gigabyte log files #1052

Description

@Mancn-Xu

What Happened?

On Logseq Desktop 2.0.1, a malformed thread-api/q request caused the graph-local db-worker-node-YYYYMMDD.log file to grow to 3,002,106,416 bytes in about one minute.

The query declared two inputs but supplied only the implicit database input:

[:find ?e
 :in $ ?property
 :where
 [?e :block/title ?property]]

The worker correctly rejected the request with:

Too few inputs passed, expected: [$ ?property], got: 1

However, log-invoke-error! logged the complete exception object. DataScript includes the received DB value in the exception's :data :got field, so serializing that exception also serialized the graph schema and datoms.

Observed impact from one real log:

  • Total file size: 3,002,106,416 bytes (2.8 GiB)
  • Total lines: 894
  • Oversized lines: 75
  • Size of each oversized line: 40,024,609 bytes
  • Total size of oversized lines: 3,001,845,675 bytes
  • Time window: 2026-08-12T15:43:03.086Z to 2026-08-12T15:44:10.047Z

This is also a privacy concern because the log contains graph titles and datoms. I am therefore not attaching the original log.

The invalid query was issued repeatedly by a caller, which is a separate caller bug. Regardless of the caller, one rejected worker request should not write an entire graph to disk.

Reproduce the Bug

  1. Start db-worker-node for a non-empty disposable DB graph with error logging enabled.
  2. Invoke thread-api/q with a query that declares :in $ ?property, but supply only the query.
  3. Inspect the graph-local db-worker-node-YYYYMMDD.log file.
  4. Observe that the :db-worker-node-invoke-failed entry contains #datascript/DB, including schema and datoms.
  5. Repeat the request and observe that the log grows by roughly the serialized size of the graph each time.

Expected Behavior

The worker should retain useful diagnostics such as status, error code, message, and method, but it should not serialize the DataScript DB or graph contents into the log.

Desktop or Mobile Platform Information

  • macOS Desktop
  • Logseq 2.0.1
  • db-worker-node revision reported by the log: b09316a
  • DB graph

Additional Context

The relevant path is src/main/frontend/worker/db_worker_node.cljs:

(log/error :db-worker-node-invoke-failed
           {:status status
            :code code
            :error error
            :message message
            :method method-kw})

Removing the raw :error value prevents its ex-data from recursively serializing the database. The existing status, code, message, and method fields preserve the actionable request context. The /v1/import-db-binary error path contains the same raw-error logging and can use the shared sanitized helper as well.

The original caller could not be identified from the worker log, but the worker-side behavior is deterministic and reproducible in a disposable graph without the original caller or graph.

Are you willing to submit a PR?

  • I'm willing to submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions