zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

Race condition in SQL console (save changes vs execute query) #4028

Closed mechanarchy closed 1 year ago

mechanarchy commented 1 year ago

Trilium Version

0.59.4

What operating system are you using?

macOS

What is your setup?

Server access only

Operating System Version

macOS Monterey 12.6.3

Description

A race condition exists in the SQL console, between changes being pushed to the backend, and the request for a query to be executed.

This mostly happens when I am actively modifying the query and then quickly press Ctrl+Enter. In the screenshots below, I:

  1. Enter the query SELECT '' and wait for the note to be saved
  2. Quickly type asd into the single quotes, and then quickly press Ctrl+Enter
  3. See that the result of the SQL query is '' and not 'asd' as expected.

Looking at the request timeline in developer tools, it is clear the race condition is present:

image image image

Error logs

No response

mechanarchy commented 1 year ago

A quick look at the code suggests the Entrypoints:runActiveNoteCommand function is where a change should be made: https://github.com/zadam/trilium/blob/6f16b4caeca3073de17527d3ebcf0283a1782464/src/public/app/components/entrypoints.js#L170-L173

By forcing another save using a command like this: https://github.com/zadam/trilium/blob/6f16b4caeca3073de17527d3ebcf0283a1782464/src/public/app/widgets/note_detail.js#L86

But I'm not sure about the cleanest way of doing it.

zadam commented 1 year ago

fixed