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

Retry on network errors and fix retries on async inserts with database/sql interface #1330

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions clickhouse_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io"
"log"
"math/rand"
"net"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -124,7 +125,10 @@ func init() {
// isConnBrokenError returns true if the error class indicates that the
// db connection is no longer usable and should be marked bad
func isConnBrokenError(err error) bool {
if errors.Is(err, io.EOF) || errors.Is(err, syscall.EPIPE) {
if errors.Is(err, io.EOF) || errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET) {
return true
}
if _, ok := err.(*net.OpError); ok {
return true
}
return false
Expand Down Expand Up @@ -276,10 +280,14 @@ func (std *stdDriver) CheckNamedValue(nv *driver.NamedValue) error { return nil
var _ driver.NamedValueChecker = (*stdDriver)(nil)

func (std *stdDriver) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
var err error
if options := queryOptions(ctx); options.async.ok {
return driver.RowsAffected(0), std.conn.asyncInsert(ctx, query, options.async.wait, rebind(args)...)
err = std.conn.asyncInsert(ctx, query, options.async.wait, rebind(args)...)
} else {
err = std.conn.exec(ctx, query, rebind(args)...)
}
if err := std.conn.exec(ctx, query, rebind(args)...); err != nil {

if err != nil {
if isConnBrokenError(err) {
std.debugf("ExecContext got a fatal error, resetting connection: %v\n", err)
return nil, driver.ErrBadConn
Expand Down
Loading