Skip to content

Fix 'Commands out of sync' error#35

Merged
ianoxley merged 7 commits intomasterfrom
commands-out-of-sync-fix
Dec 15, 2020
Merged

Fix 'Commands out of sync' error#35
ianoxley merged 7 commits intomasterfrom
commands-out-of-sync-fix

Conversation

@ianoxley
Copy link
Contributor

In a multi-threaded situation, it was possible to get a Commands out of sync error due to multiple statements being open at once.

This PR fixes this by ensuring that #close is called on each statement.

So that we can still work with any results returned from a query, we call #to_a on the result object before returning.

Ensures that `statement.close` is always called on prepared statements.

This fixes an issue where, when multiple threads are running different
queries at the same time, we can run into a `Commands out of sync`
error.
Call `#to_a` on the result so we can close the statement and still work
with the result data in the caller.
@ianoxley ianoxley self-assigned this Dec 14, 2020
Although Ruby 2.5 lets you use `ensure` in `do...end` blocks, add
`begin...end` to support older Ruby versions.

Change `test-runner` image to use Ruby 2.4.
jameshodgson
jameshodgson previously approved these changes Dec 15, 2020
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit fc71136 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 100.0% (0.0% change).

View more on Code Climate.

@ianoxley ianoxley merged commit 4f329bb into master Dec 15, 2020
@ianoxley ianoxley deleted the commands-out-of-sync-fix branch December 15, 2020 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants