mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.36k stars 1.22k forks source link

[BUG] Loop Detected in IndexNodes of LiteDB #2417

Open gaddepalli opened 4 months ago

gaddepalli commented 4 months ago

Version Which LiteDB version/OS/.NET framework version are you using. (REQUIRED) 5.0.17

Describe the bug A clear and concise description of what the bug is. when we are trying to access the corrupted LiteDB table, it is stuck and does not return any exception or timing out. It is stuck while reading the corrupted LiteDB table. I attached db and video showing the issue. Our analysis with LiteDB Studio revealed that the IndexNodes of this corrupted db are in a loop. Consequently, when attempting to fetch all data from a table, the loop prevents the query from completing.

Code to Reproduce Write a small snippet to isolate your bug and could be possible to our team test. (REQUIRED) I've attached the corrupted db file where this problem occurs, and I've added changed to the code and raised a pr. Now, if a loop is detected in the IndexNodes linkage, we'll throw a LoopDetectedException.

Expected behavior A clear and concise description of what you expected to happen. Ideally, Index Nodes should not be in loop, we need to investigate why these Index Nodes in the CollectionIndex have formed a loop. However, as a temporary solution, we should detect the loop and throw an exception since executing select all query will continue endlessly.

Screenshots/Stacktrace If applicable, add screenshots/stacktrace I've attached a video of the query to select all customers, and it stuck during its execution.

https://github.com/mbdavid/LiteDB/assets/159515214/8b0a92e6-38e0-4a30-bd51-2cfce3e31a4c

Below MyData.zip has corrupted db. MyData.zip

Additional context Add any other context about the problem here. Here's the Pull request containing the latest code changes that include the implementation to detect loops using hare tortoise algorithm and throw an exception: Please review this pull Request: https://github.com/mbdavid/LiteDB/pull/2416

Thanks