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

Timeout logic fails with errors within transactions #16

Closed
okeuday opened this issue May 6, 2014 · 5 comments
Closed

Timeout logic fails with errors within transactions #16

okeuday opened this issue May 6, 2014 · 5 comments
Labels

Comments

@okeuday
Copy link

okeuday commented May 6, 2014

I was testing using pgsql_connection:simple_query/4 with a sequence of SQL commands that create a transaction (BEGIN/(COMMIT|ROLLBACK)) and found I was able to crash the pgsql_connection pid at https://github.com/semiocast/pgsql/blob/master/src/pgsql_connection.erl#L699 due to the fun argument not handling "{error, {pgsql_error, [...proplist data...]}}" (i.e., instead it expects to always get "{set, []}"). This occurred when one of the SQL statements supplied was invalid. This should be an error that is not yet handled within pgsql_connection, since the Erlang pid should not be dying in this case.

semiocast pushed a commit that referenced this issue May 6, 2014
The crash happened when executing a statement yielding an error and
with a timeout value (not infinity). The statements sent by the driver
to change statement_timeout value failed with an error message which
was not properly handled.
@semiocast
Copy link
Collaborator

Thank you for the bug report and analysis. This bug was fixed in 693958e.

@semiocast semiocast added the bug label May 6, 2014
@okeuday
Copy link
Author

okeuday commented May 6, 2014

Thank you for the fix!

@okeuday
Copy link
Author

okeuday commented May 8, 2014

After some more testing, it seems like this fix isn't complete. When a transaction dies before the COMMIT command another simple_query function call with a ROLLBACK command should be possible, however, it doesn't work when using this driver. For some reason, the driver locks onto the last error state and doesn't allow the ROLLBACK to occur.

@semiocast semiocast reopened this May 9, 2014
@semiocast semiocast changed the title Transactions can fail Timeout logic fails with errors within transactions May 9, 2014
semiocast pushed a commit that referenced this issue May 9, 2014
Timeout now works as specified with transactions that fail. The documentation
specifies that logic would be confused with SET statement_timeout statements
or a non-infinity default value in postgresql.conf. Eventually, the timeout
could be saved to avoid setting and resetting it each time a statement
is executed with a given timeout (this optimization requires to determine
whether the session is within a transaction).
@pguyot
Copy link
Contributor

pguyot commented May 9, 2014

Michael,

Thank you for this additional report. I reviewed and fixed the logic. New tests were added corresponding to your description. Indeed, it seems you have been issuing ROLLBACK commands with a non-default (infinity) timeout.

Logic could be optimized eventually around your usage pattern if the specified timeout is always the same, as every statement with a timeout is sent with two additional statements (SET and RESET). However, this doesn't sound obvious as transaction failures resets the statement_timeout run-time parameter.

@okeuday
Copy link
Author

okeuday commented May 9, 2014

Thanks, that fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants