Repository navigation
fix(worker): answer read thread-apis before the graph is open - #13862
yuxi-liu-wired wants to merge 2 commits into
Conversation
Right after a reload the renderer sends graph-scoped read thread-apis
before the worker has opened the graph (worker-state/get-datascript-conn
is still nil). A local key fuzzer that reloads mid-session hit:
- :thread-api/get-blocks returned nil, so frontend.db.async logged
":db/block-fetch-failed ... Unexpected get-blocks response count" (the
right sidebar's Contents page);
- :thread-api/build-graph threw "No protocol method IDeref.-deref
defined for type null"; get-view-data, favorited-page? and
get-all-page-titles deref the conn the same way.
get-blocks now answers each request with a missing block ({:id id}),
which the renderer already treats as not found; the others use the
same when-let on the conn as the read handlers next to them and return
nil (false for favorited-page?). Nothing changes once the conn exists.
graph-not-open-test calls these thread-apis for a repo with no conn;
the get-blocks case fails without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
| (when-let [conn (worker-state/get-datascript-conn repo)] | ||
| (graph-view/build-graph @conn option))) |
There was a problem hiding this comment.
🔴 Global graph stalls on early reads
When build-graph runs before the graph opens, it returns nil as a successful build. load-global-graph! stores nil, leaving the graph on Preparing without an error or retry button.
Learn more
A global graph load treats any resolved value as completed graph data. Before the worker has a connection, this handler resolves nil rather than rejecting. load-global-graph! stores the nil result and clears loading, while global-graph-content renders Preparing when graph data is nil and only exposes Retry when there is a build error. The effect also tests nil as unloaded and can request again when its data map changes.
Example: Open the global graph immediately after a reload, before create-or-open-db finishes. The early build returns nil; the view has no graph and no error button instead of waiting for the graph to open and then building it.
Recommended fix: Gate the graph load in load-global-graph! on graph-open readiness or explicitly retry it when the graph becomes ready. Keep nil responses out of the successful graph-data path, and avoid an unconditional nil-result retry loop.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (if (worker-state/get-datascript-conn repo) | ||
| (get-blocks-response repo requests) | ||
| ;; Before the worker has opened the graph (e.g. right after a reload), | ||
| ;; answer every request as a missing block: the renderer expects one | ||
| ;; result per request. | ||
| (mapv (fn [{:keys [id]}] {:id id}) requests))) |
There was a problem hiding this comment.
🔍 Contents sidebar lacks an open-triggered reload
An early missing-block result leaves Contents absent. sidebar-item-inner loads only on mount; verify that graph restore remounts it.
Was this helpful? React with 👍 or 👎 to provide feedback.
A nil from :thread-api/build-graph is stored by load-global-graph! as a finished graph, which leaves the global graph view on "Preparing" with no error or retry. Before the graph is open the thrown error is the better answer (the view shows it with a retry), so build-graph is back to master's behaviour.
|
|
Superseded by #13864, which fixes the cause instead of each handler: calls for a graph that is still opening now wait for the open in |
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph; they deref the graph's nil conn and throw "No protocol method IDeref.-deref defined for type null". They now use the same when-let on the conn as the neighbouring read handlers and return nil until the graph is open (the same change for the other read handlers is logseq#13862; this file is already in this PR). property-read-thread-apis-return-nil-before-graph-opens-test calls the three for a repo with no conn; all three throw without the change.
Answer read thread-apis before the graph is open
Right after a reload the renderer sends graph-scoped read thread-apis as soon as it renders, before
:thread-api/create-or-open-dbhas run, sofrontend.worker.state/get-datascript-connis still nil for the graph. Most read handlers already wrap the conn inwhen-let; these did not::thread-api/get-blocksreturned nil, andfrontend.db.asynclogged:db/block-fetch-failed {:operation :get-block, :block "Contents", :error "Unexpected get-blocks response count" {:request-count 1, :response-count 0}}(the right sidebar's Contents page);:thread-api/get-view-data,:thread-api/favorited-page?and:thread-api/get-all-page-titlesderef the nil conn and throwNo protocol method IDeref.-deref defined for type null.:thread-api/build-graphthrows the same way but keeps that behaviour: the global graph view shows the error with a retry, while a nil would be stored as a finished graph and leave the view on "Preparing".Found by a local key fuzzer that reloads mid-session.
Change
frontend.worker.handler.block:get-blocksanswers each request with a missing block ({:id id}), which the renderer already treats as not found.frontend.worker.handler.view(get-view-data) andfrontend.worker.handler.graph(favorited-page?,get-all-page-titles): the samewhen-leton the conn as the neighbouring read handlers; they return nil (falseforfavorited-page?) until the graph is open.Nothing changes once the conn exists. Write handlers are unchanged: the renderer doesn't send them during startup, and an error is still the right answer there.
Tests
New
src/test/frontend/worker/handler/graph_not_open_test.cljs, for a repo with no conn:get-blocks-answers-each-request-before-graph-opens-test: one result per request, each a missing block (fails on master: nil).read-thread-apis-return-empty-before-graph-opens-test: view, favourite and page-title reads return nil/false without throwing.CI's unit suite and lint pass locally.