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

(Bug report) Trilium crashed after delete the Todo item in the demo #3239

Closed zhang-stephen closed 1 year ago

zhang-stephen commented 2 years ago

Trilium Version

0.56.1

What operating system are you using?

Ubuntu. Trilium is deployed by docker on ubuntu server 22.04.1 LTS.

What is your setup?

Server access only

Operating System Version

MacOS 13, to access the trilium page by Microsoft Edge.

Description

When I try to delete a todo item in the demo, I got this:

截屏2022-10-26 03 20 25

and nothing would be rendered, the page is blank. Restore the backup is the only way to get rid of this error.

zhang-stephen commented 2 years ago

it works after rebooting the trilium docker, but I still think it's a bug.

sigaloid commented 2 years ago

Are you getting a 503 error?

zhang-stephen commented 1 year ago

no error code like 503 or 404 or others. I just got a blank page without hints. I won't know what happened if I did not open the debug tool.

Oh, I forgot the point... to reproduce it, delete todo item and check the "erase notes permanently...", and you will get error like this after frontend reloading.

sigaloid commented 1 year ago

There might not have been a visible error but I believe the HTTP error would be set to something. But in most browsers that's not typically visible, sorry for not specifying.

I'm going to try and replicate this hopefully and find the root issue.

Edit: I believe I misread your comment. Are you saying the HTTP request is a 200 status? You can verify this by clicking F12, clicking requests, and reloading - the request should have a badge saying the result code.

zhang-stephen commented 1 year ago

I retried and use curl to get the HTTP status code: image

it seems the trilium works well? but I still have the error. you can see that nothing is rendered. image

sigaloid commented 1 year ago

Thanks, I can reproduce. Some error logs:

Sending message to all clients: {"type":"taskProgressCount","taskId":"iznnrmHetv","taskType":"delete-notes","progressCount":0}
Marking branches gQ19vPPsWr8K as deleted
Marking branches Alh490DT84c3 as deleted
Marking branches HlnGLyBBrjcZ as deleted
Marking branches LifnTKWh8cyd as deleted
Marking branches zs0dEjnQp8cT as deleted
Deleting note uJzphrAimUXW
Marking attributes RBzGGrNUhbvP as deleted
[Script 1mywhYUUSUMQ] Ensured note uJzphrAimUXW is in parent note oTgmQuEHXRaC with prefix undefined
[Script 1mywhYUUSUMQ] Ensured note uJzphrAimUXW is in parent note gPpmSAn6xBbn with prefix undefined
[Script 1mywhYUUSUMQ] Ensured note uJzphrAimUXW is in parent note TaPdCMB0hqp6 with prefix undefined
[Script 1mywhYUUSUMQ] Ensured note uJzphrAimUXW is in parent note QsPpikPflMq3 with prefix undefined
[Script 1mywhYUUSUMQ] Marking attributes 9kB5Uh16UK0n as deleted
[Script 1mywhYUUSUMQ] Marking attributes 2ShanoCdmhs8 as deleted
[Script 1mywhYUUSUMQ] Marking attributes GjEK2hSxHYmq as deleted
[Script 1mywhYUUSUMQ] Marking attributes iGzQAs57kZTJ as deleted
[Script 1mywhYUUSUMQ] Marking attributes xJI1142Y66gy as deleted
[Script 1mywhYUUSUMQ] Marking attributes 9eY43fw9KLVw as deleted
[Script 1mywhYUUSUMQ] Marking attributes ilZEcNoz3O3a as deleted
[Script 1mywhYUUSUMQ] Marking notes uJzphrAimUXW as deleted
[Script 1mywhYUUSUMQ] Erased branches: ["zs0dEjnQp8cT","Rvxc9CfrbmCu","gQ19vPPsWr8K","qLjIR39D30aB","Alh490DT84c3","nzW8DGu6HSjx","LifnTKWh8cyd","MOTdPNlVlyFR","HlnGLyBBrjcZ","Gse1HwBB65wM"]
[Script 1mywhYUUSUMQ] Erased attributes: ["RBzGGrNUhbvP","9kB5Uh16UK0n","2ShanoCdmhs8","GjEK2hSxHYmq","iGzQAs57kZTJ","xJI1142Y66gy","9eY43fw9KLVw","ilZEcNoz3O3a"]
[Script 1mywhYUUSUMQ] Erased notes: ["uJzphrAimUXW"]
[Script 1mywhYUUSUMQ] Sending message to all clients: {"type":"taskSucceeded","taskId":"iznnrmHetv","taskType":"delete-notes"}
Slow 200 DELETE /api/branches/HlnGLyBBrjcZ?taskId=iznnrmHetv&eraseNotes=true&last=true with 20 bytes took 24ms
JS Info: Frontend app reload: erasing notes requires reload
JS Info: Frontend app reload: notes uJzphrAimUXW is erased, need to do complete reload.
JS Info: Frontend app reload: branches Alh490DT84c3 is erased, need to do complete reload.
JS Info: Frontend app reload: branches HlnGLyBBrjcZ is erased, need to do complete reload.
JS Info: Frontend app reload: branches LifnTKWh8cyd is erased, need to do complete reload.
JS Info: Frontend app reload: branches gQ19vPPsWr8K is erased, need to do complete reload.
JS Info: Frontend app reload: branches zs0dEjnQp8cT is erased, need to do complete reload.
JS Info: Frontend app reload: attributes 2ShanoCdmhs8 is erased, need to do complete reload.
JS Info: Frontend app reload: attributes 9eY43fw9KLVw is erased, need to do complete reload.
JS Info: Frontend app reload: attributes 9kB5Uh16UK0n is erased, need to do complete reload.
JS Info: Frontend app reload: attributes GjEK2hSxHYmq is erased, need to do complete reload.
JS Info: Frontend app reload: attributes RBzGGrNUhbvP is erased, need to do complete reload.
JS Info: Frontend app reload: attributes iGzQAs57kZTJ is erased, need to do complete reload.
JS Info: Frontend app reload: attributes ilZEcNoz3O3a is erased, need to do complete reload.
JS Info: Frontend app reload: attributes xJI1142Y66gy is erased, need to do complete reload.
GET /api/notes/uJzphrAimUXW returned 404 with response "Note uJzphrAimUXW has not been found."
404 GET /api/notes/uJzphrAimUXW with 37 bytes took 0ms
Generated CSRF token 9SBDr4d3-VQra1VsQQJ-HVOKl7mVeIRUFZQk with secret undefined
JS Error: Error when calling GET /api/notes/uJzphrAimUXW: 404 - Note uJzphrAimUXW has not been found.
Stack: Error
    at Object.C [as logError] (http://127.0.0.1:37840/app-dist/desktop.js:2:102748)
    at Object.throwError (http://127.0.0.1:37840/app-dist/desktop.js:2:87904)
    at c (http://127.0.0.1:37840/app-dist/desktop.js:2:84559)
    at async EventEmitter.<anonymous> (http://127.0.0.1:37840/app-dist/desktop.js:2:85411)
200 GET /api/options with 5675 bytes took 1ms
200 GET /api/tree with 25284 bytes took 1ms
200 GET /api/keyboard-actions with 11944 bytes took 0ms
200 GET /api/keyboard-shortcuts-for-notes with 2 bytes took 0ms
200 GET /api/script/widgets with 2717 bytes took 0ms
websocket client connected
200 POST /api/tree/load with 1697 bytes took 0ms

Upon regular Ctrl-R:

JS Error: Uncaught error: Message: Uncaught TypeError: Cannot read properties of undefined (reading 'activeNtxId'), URL: http://127.0.0.1:37840/app-dist/desktop.js, Line: 2, Column: 48625, Error object: {}, Stack: TypeError: Cannot read properties of undefined (reading 'activeNtxId')
    at http://127.0.0.1:37840/app-dist/desktop.js:2:48625
    at HTMLDocument.<anonymous> (http://127.0.0.1:37840/app-dist/desktop.js:2:92410)
    at HTMLDocument.handleObj.handler (http://127.0.0.1:37840/libraries/jquery.hotkeys.js:183:30)
    at HTMLDocument.dispatch (http://127.0.0.1:37840/libraries/jquery.min.js:2:43064)
    at HTMLDocument.v.handle (http://127.0.0.1:37840/libraries/jquery.min.js:2:41048)
Stack: Error
    at Object.C [as logError] (http://127.0.0.1:37840/app-dist/desktop.js:2:102748)
    at Gn.window.onerror (http://127.0.0.1:37840/app-dist/desktop.js:2:543275)

Only restarting the app fixes it.

Uncaught (in promise) Error: Branch "hrClFU2e2QG5" has no child note "ldPcbfdaU2Aa"
    prepareNode http://localhost:8080/app/widgets/note_tree.js:673
    prepareChildren http://localhost:8080/app/widgets/note_tree.js:627
    prepareNode http://localhost:8080/app/widgets/note_tree.js:697
    prepareChildren http://localhost:8080/app/widgets/note_tree.js:627
    prepareNode http://localhost:8080/app/widgets/note_tree.js:697
    prepareChildren http://localhost:8080/app/widgets/note_tree.js:627
    prepareNode http://localhost:8080/app/widgets/note_tree.js:697
    prepareChildren http://localhost:8080/app/widgets/note_tree.js:627
    prepareNode http://localhost:8080/app/widgets/note_tree.js:697
    prepareChildren http://localhost:8080/app/widgets/note_tree.js:627
    prepareNode http://localhost:8080/app/widgets/note_tree.js:697
    prepareRootNode http://localhost:8080/app/widgets/note_tree.js:595
    initFancyTree http://localhost:8080/app/widgets/note_tree.js:293
    doRender http://localhost:8080/app/widgets/note_tree.js:235
    render http://localhost:8080/app/widgets/basic_widget.js:79
    doRender http://localhost:8080/app/widgets/containers/container.js:8
    render http://localhost:8080/app/widgets/basic_widget.js:79
    doRender http://localhost:8080/app/widgets/containers/container.js:8
    render http://localhost:8080/app/widgets/basic_widget.js:79
    showWidgets http://localhost:8080/app/services/app_context.js:41
    start http://localhost:8080/app/services/app_context.js:32
    async* http://localhost:8080/app/desktop.js:28
    promise callback* http://localhost:8080/app/desktop.js:26

Looks like it's tracing down the tree down to the note, but since it's been deleted, it fails at https://github.com/zadam/trilium/blob/master/src/public/app/widgets/note_tree.js#L673.

The call to branch.getNoteFromCache() seems relevant - it returns undefined if the note was deleted. It should instead check if it's undefined, and if so, process it from the parent (I assume?).

zadam commented 1 year ago

Hi, thanks for reporting and the detective work.

This is a specific problem with task manager - part of its functionality is that it places the task note into different parent notes based on the task status/attributes. But this conflicts with the deletion process - the task manager script recreates the "branch" immediately after its deletion, which then creates an inconsistency in the database (from which trilium recovers during startup). The script needs to be able to detect that the whole note is being deleted, even when handling attribute events. Should be fixed in the next release.