-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Portal not being implicitly destroyed on transaction finish #42912
Comments
Thanks for the report! @mjibson is this the expected behavior? I can't quite remember. |
This is the expected behavior. Our current implementation has known limitations. One of them is that it doesn't process any query messages. So even in this case, where the portal is implicitly closed, our implementation doesn't read ahead to check that it's a "Why not just have it look ahead and see if the first statement in the next query is While we could maybe do this, this is exactly where our current implementation gets very hard to do correctly. We knew all of this going in, and you have hit exactly the point at which we decided to draw a line to avoid a great deal of complication. We will however keep track of this issue and problem. If more people start to report it we may consider increasing the priority of this feature. (By "this feature" I mean supporting exactly this use case where there's a txn ending with an open portal.) |
Would it really be hard to support this? The way I'd imagine this to work is to pop out |
63677: sql/pgwire: implicitly destroy portal on txn finish r=jordanlewis a=rafiss fixes #42912 touches #40195 This also includes a commit to fix an error message hint that seems to be accidentally using `WithSafeDetails`, which is meant for sentry reporting. (Originally added in #40197.) Release note (sql change): Previously, committing a transaction when a portal was suspended would cause a "multiple active portals not supported" error. Now, the portal is automatically destroyed. Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com>
Describe the problem
Using to run a query in Java: when the query is inside a transaction with fetch size set, a cursor/portal is created on the server.
Upon committing the transaction without closing the ResultSet, the follwing error occurs:
To Reproduce
Run CockroachTest
(the test is "standalone" and needs to have a CockroachDB or PostgreSQL container running; the commands used to start the containers are shown in the test comments)
Expected behavior
The test has 4 cases: a
SELECT *
query is ran using fetch size 0 or 2 (which is less than the size of the ResultSet); in addition, the query may run with or without a transaction.When running without transaction, the fetch size is ignored and no problems occur (I suppose this is due to the limitations that also apply to PostgreSQL, using "fetch size" needs server cursors which only live for the duration of a transaction).
When running fetch size 0, the feature is disabled and no problems occur.
When running fetch size 2:
Even though it is a good practice to close the ResultSets (as well as other Closeable objects), the patch in #33423 leads me to believe that the behavior to expect is the same as PostgreSQL: the cursors/portals should be implicitly closed when the transaction is done.
Environment:
CockroachDB 19.1.X, 19.2.X or PostgreSQL 9.6.X (or newer)
The text was updated successfully, but these errors were encountered: