Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mechanarchy opened this issue Jun 14, 2023 · 2 comments
Closed

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

mechanarchy opened this issue Jun 14, 2023 · 2 comments

Comments

@mechanarchy
Copy link
Contributor

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
Copy link
Contributor Author

A quick look at the code suggests the Entrypoints:runActiveNoteCommand function is where a change should be made:

} else if (note.mime.endsWith("env=backend")) {
await server.post(`script/run/${note.noteId}`);
} else if (note.mime === 'text/x-sqlite;schema=trilium') {
const resp = await server.post(`sql/execute/${note.noteId}`);

By forcing another save using a command like this:

await server.put(`notes/${noteId}/data`, data, this.componentId);

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

@zadam
Copy link
Owner

zadam commented Jun 15, 2023

fixed

@zadam zadam closed this as completed Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants