Fix for 7403 - a race condition bug. #7404
Open
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 for the bug described here: #7403
The fix removes the global call to "rows.Err()" from the generic Scan method, as it's something that should be done by the caller when the caller knows that the method can be called in a safe way (the rows instance is explicitly or implicitly closed).
By calling the method after making sure that the
rows
instance is closed, the code protects the call against the race condition described in the issue.The fixed
Scan()
method is also called internally, so I also made sure that potential errors won't be missed there, by calling theErr()
method after making sure that therows
instance is closed. It's 100% safe, because theNext()
method called there ensures that the instance is closed and releases the potential read lock which may be left byScan()
method.I didn't add a dedicated test case, because the bug causes a race condition which is not easy to reproduce. If there was a way to mock the whole rows instance then it could be probably checked. All existing test cases passed.