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

Consume ReadyForQuery message after an error over SQL #7558

Closed
wants to merge 2 commits into from

Conversation

aljazerzen
Copy link
Contributor

@aljazerzen aljazerzen commented Jul 15, 2024

Trying to fix #7471

@msullivan
Copy link
Member

This seems basically reasonable to me, but I'd like @fantix to take a look, since I don't understand the state machine fully.

In particular, I don't understand the intricacies of send_sync_on_error

Copy link
Member

@fantix fantix left a comment

Choose a reason for hiding this comment

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

👍

else:
break

# don't break, because we want to also consume ReadyForQuery
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# don't break, because we want to also consume ReadyForQuery
# don't break, because we want to also exhaust the
# remaining buffer with "ignore_till_sync" and consume
# ReadyForQuery if there is one

Copy link
Member

@fantix fantix Jul 16, 2024

Choose a reason for hiding this comment

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

I'm sorry. Now, I think it was right to break here - because it only breaks the inner loop that handles pg responses for the outer loop's current action, and an ErrorResponse does mean the action is resolved.

Then, the outer loop will continue with ignore_till_sync=True and skip all the actions until SYNC, which is guaranteed to be there in pg_ext.simple_query() (which is the only case when send_sync_on_error=True). The ReadyForQuery will then be processed and forwarded to the frontend correctly.

We had an issue because send_sync_on_error=True sent an extra SYNC to PG, and we didn't have a corresponding action to consume its resulting ReadyForQuery.

The first returning value of _parse_sql_extended_query() simply means that the frontend should remain in its own ignore_till_sync mode. For simple query, this returned value is simply ignored because simple query should always clear ignore_till_sync state returning a ReadyForQuery (equivalent to finalizing with SYNC).

#7560 should do

@fantix
Copy link
Member

fantix commented Jul 15, 2024

Oh wait I just saw Sully saying send_sync_on_error


Hmm, I think that was just doing the same thing as this PR, but in a wrong way, as we already included a SYNC in pg_ext.simple_query() 🤔 let me do some more experiments.

else:
break

# don't break, because we want to also consume ReadyForQuery
Copy link
Member

@fantix fantix Jul 16, 2024

Choose a reason for hiding this comment

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

I'm sorry. Now, I think it was right to break here - because it only breaks the inner loop that handles pg responses for the outer loop's current action, and an ErrorResponse does mean the action is resolved.

Then, the outer loop will continue with ignore_till_sync=True and skip all the actions until SYNC, which is guaranteed to be there in pg_ext.simple_query() (which is the only case when send_sync_on_error=True). The ReadyForQuery will then be processed and forwarded to the frontend correctly.

We had an issue because send_sync_on_error=True sent an extra SYNC to PG, and we didn't have a corresponding action to consume its resulting ReadyForQuery.

The first returning value of _parse_sql_extended_query() simply means that the frontend should remain in its own ignore_till_sync mode. For simple query, this returned value is simply ignored because simple query should always clear ignore_till_sync state returning a ReadyForQuery (equivalent to finalizing with SYNC).

#7560 should do

@aljazerzen
Copy link
Contributor Author

Great, thanks fantix.

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.

SQL adapter: unexpected message type 'Z' in IDLE state
3 participants