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

Portal not being implicitly destroyed on transaction finish #42912

Closed
jmf-tls opened this issue Dec 3, 2019 · 3 comments · Fixed by #63677
Closed

Portal not being implicitly destroyed on transaction finish #42912

jmf-tls opened this issue Dec 3, 2019 · 3 comments · Fixed by #63677
Assignees
Labels
C-investigation Further steps needed to qualify. C-label will change. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@jmf-tls
Copy link

jmf-tls commented Dec 3, 2019

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:

org.postgresql.util.PSQLException: ERROR: unimplemented: multiple active portals not supported
  Hint: You have attempted to use a feature that is not yet implemented.
See: https://github.com/cockroachdb/cockroach/issues/40195

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)

@jordanlewis
Copy link
Member

Thanks for the report!

@mjibson is this the expected behavior? I can't quite remember.

@jordanlewis jordanlewis added the C-investigation Further steps needed to qualify. C-label will change. label Dec 8, 2019
@maddyblue
Copy link
Contributor

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 COMMIT statement.

"Why not just have it look ahead and see if the first statement in the next query is COMMIT?"

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.)

@andreimatei
Copy link
Contributor

Would it really be hard to support this? The way I'd imagine this to work is to pop out limitedCommandResult when we see anything but a ExecPortal, consider the query finished (so don't allow a further ExecPortal on it) and then have the portal be naturally destroyed at the end of the transaction.

@rafiss rafiss assigned rafiss and unassigned maddyblue Apr 14, 2021
craig bot pushed a commit that referenced this issue Apr 27, 2021
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>
@craig craig bot closed this as completed in 9ae5896 Apr 27, 2021
@exalate-issue-sync exalate-issue-sync bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-investigation Further steps needed to qualify. C-label will change. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants