Skip to content

Commit

Permalink
Handle epipe errors
Browse files Browse the repository at this point in the history
Presently, if the tcp session to the server closes, we will emit
broken pipe errors potentially until we reach ConnMaxLifetime.

Since EPIPE means that the tcp session is dead (ie we received a
RST packet from the server), there is no point in attempting to
proceed past that point: set the connection as closed.
  • Loading branch information
n-oden committed Jan 13, 2023
1 parent 930a6c9 commit 6328c62
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package clickhouse
import (
"context"
"crypto/tls"
"database/sql/driver"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2/resources"
"github.com/pkg/errors"
"log"
"net"
"os"
"syscall"
"time"

"github.com/ClickHouse/ch-go/compress"
Expand Down Expand Up @@ -226,6 +228,11 @@ func (c *connect) sendData(block *proto.Block, name string) error {
return err
}
if err := c.flush(); err != nil {
if errors.Is(err, syscall.EPIPE) {
c.debugf("[send data] pipe is broken, closing connection")
c.closed = true
return driver.ErrBadConn
}
return err
}
defer func() {
Expand Down

0 comments on commit 6328c62

Please sign in to comment.