pgx
pgx copied to clipboard
tls: failed to send closeNotify alert (but connection was closed anyway): write tcp xxx.xxx.xxx.xxx:57192->xxx.xxx.xxx.xxx:5432: write: broken pipe
Hi Guys,
In our application I am using the pgx postgresql driver along with golang version 1.16.2 to update Azure Postgres DB(its support TLS 1.0, 1.1 and 1.2). The data is updated properly in the Azure postgresql DB, but the problem is while closing the DB (i.e sql.DB.Close()) I am getting the below error from the database/sql package.
tls: failed to send closeNotify alert (but connection was closed anyway): write tcp xxx.xxx.xxx.xxx:57192->xxx.xxx.xxx.xxx:5432: write: broken pipe
The pgx driver with golang version 1.15.10, I am getting a different error
write tcp x.x.x.x:56162->x.x.x.x:5432: write: broken pipe
This problem is not coming in the pq postgres driver. My queries are
Do I need to do anything related to TLS configuration in pgx driver? if so how I to do it? Is pgx incompatible with Azure Postgresql DB? Is any configuration I need to do in the Azure postgresql DB server? which TLS version the pgx postgres client is using?
Sample code
import (
"fmt"
"sync"
"context"
"database/sql"
"github.com/cenkalti/backoff"
_ "github.com/jackc/pgx/v4/stdlib"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
"time"
)
func main () {
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
DBupdateTest(ctx)
<-ctx.Done()
log.Info("Done signal received")
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
select {
case <-sigs:
cancel()
log.Info("Stop Signal received")
}
wg.Wait()
os.Exit(0)
}
func DBupdateTest(ctx context.Context){
db, err := sql.Open("pgx", os.Getenv("DATABASE_URL"))
if err != nil {
return
}
defer func() {
if err := db.Close(); err != nil {
log.Errorf("DB close failed: %v", err)
} else {
log.Info("DB successfully closed")
}
}()
log.Info("set open 1 to set idle 1")
db.SetMaxOpenConns(1)
db.SetMaxIdleConns(1)
err = db.Ping()
if err != nil {
log.Errorf("ping failed %v", err)
return
}
}
```
One more finding is database/sql client with pgx driver is not sending the [FIN, ACK] packet while terminating the DB connection, It forcefully close the socket, so the Postgersql DB server sent the [RST, ACK]
@jackc do you have any update on this issue, please
We have the same problem
Any update on this issue.
Hitting the exact same error but with logstash:
error closing connection to logstash host example.com: tls: failed to send closeNotify alert (but connection was closed anyway): write tcp xxxxx:55830->xxxxxxx:5000: write: connection reset by peer, reconnecting...
We are seeing the same error.
funny, I see same error with azure mysql too
Happens with AWS Aurora as well. With Aurora MySQL too, even though it's a different driver.
Kind of makes one think it's Go TLS issue.