Fixed orphaned nodes blocking resume & nil pointer crash#327
Open
Pranav-1100 wants to merge 2 commits intostoracha:mainfrom
Open
Fixed orphaned nodes blocking resume & nil pointer crash#327Pranav-1100 wants to merge 2 commits intostoracha:mainfrom
Pranav-1100 wants to merge 2 commits intostoracha:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes issue #258 where uploads couldn't resume if a node was left orphaned (created in the DB but not linked to the upload) after a crash.
I initially tried to fix this by adding a DeleteNode rollback, but after testing I realized that wouldn't work for hard crashes (like power loss) where the cleanup code never runs.
So instead, I changed the logic to check completion using the node_uploads table rather than just the nodes table. Now, if a node exists in the database but isn’t linked to the current upload, we treat it as incomplete and attempt to link it again. I also updated the SQL insert query so that these cases don’t cause duplicate errors.
Additionally, I fixed a segmentation fault in ReadNodeFromDatabase by checking whether path and offset pointers are nil before dereferencing them. This prevents crashes when reading nodes with null values.
To verified this:-
I created a local test case that simulates an orphaned UnixFS node valid in the DB but missing from node_uploads.
Before the fix: The test failed because the system assumed the node was already done and skipped linking it.
After the fix: The test passed the system correctly detected the missing link and recovered the node.