Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple prepared stmt registraion #539

Merged
merged 6 commits into from
May 18, 2022

Conversation

G1gg1L3s
Copy link
Contributor

@G1gg1L3s G1gg1L3s commented May 17, 2022

This PR solves double registration of prepared statements. They are registered twice: after Parse and ParseComplete, but because of a race condition, the pending statement can be replaced by another. Then, this triggers registration of a nil value as a statement.

To solve the problem, this PR removes the second registration.

There is one issue though: prepared statements are never cleaned, even ones that contain errors. This requires a large redesigning of the whole packet processing protocol. So, for now, we have a small memory leakage in a connection. But on practice this should not be an issue.

Checklist

The test simulates the situation when two "parse" packets arrive
before their responses, which can cause a data race of pending
prepared statements.
It happens twice: after `Parse` and `ParseComplete` packes. Remove
the second case.
[skip ci]
const sizeLen = 4
const nullLen = 1

func writeParsePacket(w io.Writer, name string, stmt string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use existing logic of encoding statements - https://github.com/cossacklabs/acra/blob/master/decryptor/postgresql/utils.go#L82 ?

@G1gg1L3s G1gg1L3s merged commit cf2ae64 into master May 18, 2022
@G1gg1L3s G1gg1L3s deleted the G1gg1L3s/T2567-fix-multiple-stmt-registraion branch May 18, 2022 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants