trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.3k stars 2.97k forks source link

JDBC TrinoConnection#close do not cancel running queries #7587

Closed kokosing closed 2 years ago

kokosing commented 3 years ago

It is not well specified by JDBC standard as JDBC Connection#close javadoc says:

Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released. ... It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined.

See If the close method is called and there is an active transaction, the results are implementation-defined..

However this is the way DBeaver cancel the running query, by closing the connection and they claim it works this way for MySQL, PostgreSQL, Oracle and others in https://github.com/dbeaver/dbeaver/issues/3094#issuecomment-628222837

hashhar commented 3 years ago

Notably MySQL and SQL Server don't cancel the query this way. SQL Server driver tries to drain the connection and MySQL waits for a client timeout (configurable on the server).

findepi commented 3 years ago

It is not well specified by JDBC standard as JDBC Connection#close javadoc says:

Please check the JDBC spec. I recall seeing somewhere that connection close must implciitly close statements and results sets.

kokosing commented 3 years ago

From: https://download.oracle.com/otn-pub/jcp/jdbc-4_1-mrel-spec/jdbc4.1-fr-spec.pdf?AuthParam=1618515120_667f42e8665c98b8ab8eee8c1840a718

9.4.4.1 Connection.close An application calls the method Connection.close() to indicate that it has finished using a connection. All Statement objects created from a given Connection object will be closed when the close method for the Connection object is called.

They mention that it should close Statement which means:

Closing Statement Objects An application calls the method Statement.close to indicate that it has finished processing a statement. All Statement objects will be closed when the connection that created them is closed. However, it is good coding practice for applications to close statements as soon as they have finished processing them. This allows any external resources that the statement is using to be released immediately.

Then, it is a bug.

ebyhr commented 2 years ago

Closing as #7819. #7918 should be handled as a separated issue.