Skip to content

At time DB reconnect fail with read tcp [::1]:49528->[::1]:5432: read: connection reset by peer #835

Open
@meetme2meat

Description

@meetme2meat

Well, I have a sample script which I have been using to understand whether or how the lib/pq handle the reconnect.

package main

import (
	"database/sql"
	"fmt"
	"log"
	"time"

	"github.com/lib/pq"
)

func main() {
	url := "postgres://werain:@localhost/postgres?sslmode=disable&application_name=reconnect"
	connStr, err := pq.ParseURL(url)
	conn, err := sql.Open("postgres", connStr)
	if err != nil {
		log.Fatal(err)
	}
	for {
		result, err := conn.Exec("select 1;")
		if err != nil {
			fmt.Println(err)
			time.Sleep(10 * time.Second)
		}
		fmt.Println(result.RowsAffected())
		time.Sleep(5 * time.Second)
	}
}

I see the reconnect working sometime but there are time when I see the following error

read tcp [::1]:49528->[::1]:5432: read: connection reset by peer

Now I'm not sure why it works sometimes and does not work the other time. Is this something need to handle by the individual client(i.e reconnect) here?

NOTE: I'm not entirely sure if this issue is database/sql or lib/pq please help me guide through this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions