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

driver: bad connection #336

Closed
necryin opened this issue Dec 16, 2020 · 6 comments
Closed

driver: bad connection #336

necryin opened this issue Dec 16, 2020 · 6 comments

Comments

@necryin
Copy link

necryin commented Dec 16, 2020

Hi. I found inconsistent with database/sql in common case:

...
tx, _ := conn.Begin()
stmt, _ := tx.Prepare("Some insert query") <-- ErrBadConn
...

In other drivers (where connection checked in Begin()) I will get this error in Begin() and it will be retried (this logic is in database/sql). But in clickhouse driver (where as i see no real Begin() queries) I got ErrBadConn in Prepare() where no retry logic in database/sql.

@acynothia
Copy link

same issue

@acynothia
Copy link

db.SetConnMaxLifetime(15*time.Minute) seems working well.

@yzx-fish
Copy link

same issue.

@sashayakovtseva
Copy link

sashayakovtseva commented Mar 1, 2021

same issue with batch insert of data in transactions. here are debug logs from CH server (names in sql queries are cut out):

[clickhouse][connect=5][hello] -> Golang SQLDriver 1.1.54213
[clickhouse][connect=5][hello] <- ClickHouse 19.16.54427 (Etc/UTC)

// the rest of app logs

[clickhouse][connect=5][begin] tx=false, data=false
[clickhouse][connect=5][cancel] <- finished
[clickhouse][connect=5][prepare]
		INSERT INTO ... VALUES (? ...)

[clickhouse][connect=5][send query]
		INSERT INTO
			...
	 VALUES
[clickhouse][connect=5][read meta] <- data: packet=1, columns=6, rows=0
[clickhouse][connect=5][commit] tx=true, data=true
[clickhouse][connect=5][process] <- end of stream
[clickhouse][connect=5][stmt] close

// the rest of app logs

[clickhouse][connect=5][begin] tx=false, data=false
[clickhouse][connect=5][cancel] <- finished
[clickhouse][connect=5][prepare]
		INSERT INTO ... VALUES (? ...)

[clickhouse][connect=5][send query]
		INSERT INTO
			...
	 VALUES
[clickhouse][connect=5][connect] read error: EOF
[clickhouse][connect=5][rollback] tx=true, data=false
// at this point I have "driver: bad connection" during stmt.Prepare() in app logs

upd: nevermind. my issue is caused by HAProxy in front of the cluster. direct connection works like a charm.

@scarbo87
Copy link

@sashayakovtseva did you find a solution with HAProxy? I have the same problem.

@sashayakovtseva
Copy link

@sashayakovtseva did you find a solution with HAProxy? I have the same problem.

nope, I switched to direct connection.

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

No branches or pull requests

6 participants