fix: prevent batch infinite loop with arg length#1794
Merged
kyleconroy merged 3 commits intosqlc-dev:mainfrom Sep 8, 2022
Merged
fix: prevent batch infinite loop with arg length#1794kyleconroy merged 3 commits intosqlc-dev:mainfrom
kyleconroy merged 3 commits intosqlc-dev:mainfrom
Conversation
Contributor
Author
|
🤔 This is the test failure -- |
kyleconroy
requested changes
Sep 1, 2022
Collaborator
kyleconroy
left a comment
There was a problem hiding this comment.
Looking over the generated code, I think there's a cleaner way to implement the callbacks without having the check the return value of the error.
func (b *UpdateValuesBatchResults) Exec(f func(int, error)) {
defer b.br.Close() // Close is safe to call multiple times
for i := 0; i < b.tot; i++ {
if b.closed {
f(i, errrors.New("batch already closed"))
continue
}
_, err := b.br.Exec()
if f != nil {
f(i, err)
}
}
}
func (b *UpdateValuesBatchResults) Close() error {
return b.closed = true
return b.br.Close()
}Thoughts?
Contributor
Author
|
Oh yeah that's super clean, thanks! I'll circle back around and request another review after I've updated everything. |
dc8a552 to
d262908
Compare
d262908 to
7c6ac10
Compare
Contributor
Author
|
kyleconroy
approved these changes
Sep 8, 2022
jlisthood
pushed a commit
to jlisthood/sqlc
that referenced
this pull request
Apr 26, 2023
jlisthood
pushed a commit
to jlisthood/sqlc
that referenced
this pull request
Apr 28, 2023
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.
Because the batch queries are only being closed when checking for 2 errors (batch results closed or no result), other errors cause the generated code to infinite loop. This changes from a for loop that only breaks on checking the errors to a for loop that also considers the the total number of params passed in.
Some errors will not infinite loop if you close the results yourself. However, there are other errors that you can't close --
Bad queries typically happen in tests, but the infinite loop has eaten up >20Gb of RAM within a few minutes for me before.
This is usually what happens. It infinite loops, so I can't interrupt the process, and then I have to do
ps aux | grep <>to find and kill the process manually:Fixes #1678 (which was closed by the reporter since they found a workaround)