Skip to content

Improve error message when query is canceled during streaming#507

Closed
neilvcarvalho wants to merge 1 commit intoged:masterfrom
neilvcarvalho:nc-streaming-error
Closed

Improve error message when query is canceled during streaming#507
neilvcarvalho wants to merge 1 commit intoged:masterfrom
neilvcarvalho:nc-streaming-error

Conversation

@neilvcarvalho
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
Collaborator

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

@neilvcarvalho
Copy link
Copy Markdown
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