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

Check connection liveness in beginTx #421

Merged
merged 2 commits into from Oct 8, 2021

Conversation

saydamir
Copy link
Contributor

@saydamir saydamir commented Oct 8, 2021

This commit fixes for #213.

If the connection closes from the server side for some reason, the database driver returns driver.ErrBadConn to database/sql.

Usually, database/sql retries a request, assuming that the error occurs in a function that could be called first after retrieving a connection from the pool.
But beginTx in clickhouse-go doesn't perform any network interaction and driver.ErrBadConn is returned later in the transaction. database/sql doesn't retry it because assumes that connection is alive - beginTx didn't return the error.

This commit adds a method to check the connection liveness and performs that check in beginTx function.

The check is taken from go-sql-driver/mysql#934.

There is no way to check the liveness of a secure connection, as long as there is no access to raw TCP net.Conn in clickhouse-go.

This commit fixes for ClickHouse#213.

If the connection closes from the server side for some reason, the database driver returns driver.ErrBadConn to database/sql.

Usually, database/sql retries a request, assuming that the error occurs in a function that could be called first after retrieving a connection from the pool.
But beginTx in clickhouse-go doesn't perform any network interaction and driver.ErrBadConn is returned later in the transaction. database/sql doesn't retry it because assumes that connection is alive - beginTx didn't return the error.

 This commit adds a method to check the connection liveness and performs that check in beginTx function.

 The check is taken from go-sql-driver/mysql#934.

There is no way to check the liveness of a secure connection, as long as there is no access to raw TCP net.Conn in clickhouse-go.
@CLAassistant
Copy link

CLAassistant commented Oct 8, 2021

CLA assistant check
All committers have signed the CLA.

@kshvakov
Copy link
Collaborator

kshvakov commented Oct 8, 2021

Thanks!

@kshvakov kshvakov merged commit 2987a5c into ClickHouse:master Oct 8, 2021
@saydamir
Copy link
Contributor Author

saydamir commented Oct 8, 2021

@kshvakov issues can probably be closed #213 #214 #336

@saydamir saydamir deleted the connection_check_in_begin_tx branch October 8, 2021 12:58
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.

None yet

3 participants