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

Improve error message when query is canceled during streaming #507

Closed
wants to merge 1 commit into from

Conversation

neilvcarvalho
Copy link

@neilvcarvalho neilvcarvalho commented Mar 17, 2023

When streaming a result in single row mode, if this query is aborted - either because it timed out or some other reason -, ruby-pg raises the error:

PG::InvalidChangeOfResultFields: number of fields changed in single row
mode from X to 0 - this is a sign for intersection with another query

This error message is misleading and might confuse people. The number of fields changed to 0 because the result stopped being streamed.

This commit adds a different error message using the same exception class, explaining that the query was canceled or timed out.

When streaming a result in single row mode, if this query is aborted -
either because it timed out or some other reason -, `ruby-pg` raises the
error:

```
PG::InvalidChangeOfResultFields: number of fields changed in single row
mode from X to 0 - this is a sign for intersection with another query
```

This error message is misleading and might confuse people.

This commit adds a different error message, using the same exception
class, explaining that the query was canceled or timed out.
@neilvcarvalho
Copy link
Author

My initial thought would be to raise the original error from the database, but I couldn't find a way to do that. I'm not very familiar with C code, though. I'd appreciate help doing that.

larskanis added a commit to larskanis/ruby-pg that referenced this pull request Mar 21, 2023
This ensures that the nfield-check doesn't hide errors like statement timeout.

Now the new PGresult is assigned to the streaming PG::Result, even if it has a different number of fields.
This avoids leaking the memory of the wrong PGresult, but would lead to wrong fields, if the PG::Result is used afterwards.

Fixes ged#507
larskanis added a commit to larskanis/ruby-pg that referenced this pull request Mar 21, 2023
This ensures that the nfield-check doesn't hide errors like statement timeout.

Now the new PGresult is assigned to the streaming PG::Result, even if it has a different number of fields.
This avoids leaking the memory of the wrong PGresult, but would lead to wrong fields or segfaults, if the PG::Result is used afterwards.
Therefore the result is getting cleared before the raise.

Fixes ged#507
larskanis added a commit to larskanis/ruby-pg that referenced this pull request Mar 21, 2023
This ensures that the nfield-check doesn't hide errors like statement timeout.

Now the new PGresult is assigned to the streaming PG::Result, even if it has a different number of fields.
This avoids leaking the memory of the wrong PGresult, but would lead to wrong fields or segfaults, if the PG::Result is used afterwards.
Therefore the result is getting cleared before the raise.

Thanks to Neil Carvalho @neilvcarvalho for the test case!

Fixes ged#507
@larskanis
Copy link
Collaborator

I opened #510 to fix this issue. It raises the original exception.

@neilvcarvalho
Copy link
Author

Thank you, @larskanis! That was a good async pairing session 😁

I'm closing this PR in favor of #510

@neilvcarvalho neilvcarvalho deleted the nc-streaming-error branch March 22, 2023 13:18
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.

2 participants