jackc / jackc/pgx

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

Open
#984 9 comments 7 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

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
}
}
```

Contributor guide

Open the contributing guide

Research direction

Begin with the sample's database/sql DB.Close path and the github.com/jackc/pgx/v4/stdlib driver, reproducing against Azure PostgreSQL with the stated Go versions. Done means determining whether pgx causes the closeNotify/broken-pipe error and documenting or testing the relevant TLS and connection-close behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.