fix multi-blob insert queries (fixes #394)#395
Open
HeyyCzer wants to merge 1 commit intohgourvest:masterfrom
Open
fix multi-blob insert queries (fixes #394)#395HeyyCzer wants to merge 1 commit intohgourvest:masterfrom
HeyyCzer wants to merge 1 commit intohgourvest:masterfrom
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.
Fix: Multiple non-null BLOB parameters causing silent failure or "Invalid BLOB handle" error
Problem
When a single SQL statement contained 2 or more non-null BLOB parameters, one of two failures occurred:
commit()succeeded, but the row was never written to the databaseRETURNINGwas usedRoot Cause
Two compounding issues in
PrepareParamsinsideexecuteStatement(lib/wire/connection.js):Concurrent BLOB uploads: parameters were processed in a synchronous
forloop using a countdown (wait/done) pattern. All BLOB parameters firedcreateBlob2simultaneously, interleavingop_create_blob2requests before any responses were received, corrupting the_queueresponse ordering.Deferred
closeBlob:closeBlobused_queueEvent(callback, defer=true), which on protocol >= v11 sends theop_close_blobpacket with the lazy-send flag and calls the callback immediately without waiting for server confirmation. Even after fixing the loop, the next BLOB'sop_create_blob2was sent before the server had finished processing the previous blob's close, resulting in "Invalid BLOB handle".Fix
Replaced the concurrent
forloop with a sequentialstep(i)recursive function — each parameter is fully processed before the next one starts.Added a
deferparameter tocloseBlob(defaulttrueto preserve existing behavior). InsideputBlobData,closeBlobis called withdefer=false, forcing the server to acknowledge the close before the next BLOB upload begins.Impact