dbconn

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureConnReadDeadline added in v0.1.9

func ConfigureConnReadDeadline(poolConfig *pgxpool.Config)

ConfigureConnReadDeadline configures pool connections with a per-read deadline so that reads on dead connections fail instead of hanging indefinitely.

We use a custom DialFunc that wraps every net.Conn with deadlineConn, which calls SetReadDeadline before each Read. Pool callbacks like AfterConnect or BeforeAcquire only fire once, so they can only set a single absolute deadline that expires even if the connection is healthy. Wrapping net.Conn lets us reset the deadline on every Read call.

The read timeout is set to 60 seconds, which is more than enough for read-set validation and commit operations. This can be made configurable if needed.

On macOS, Docker Desktop runs a userspace TCP proxy inside a Linux VM. When a container dies the proxy does not immediately close forwarded connections, so reads hang indefinitely. The deadlineConn wrapper ensures stuck reads fail within the timeout, allowing the pool to replace them. On Linux, reads already fail immediately via TCP RST when a node dies, so the wrapper is harmless.

func DataSourceName

func DataSourceName(d DataSourceNameParams) (string, error)

DataSourceName returns the data source name of the database.

Types

type DataSourceNameParams

type DataSourceNameParams struct {
	Username        string
	Password        string
	Database        string
	EndpointsString string
	LoadBalance     bool
	TLS             DatabaseTLSConfig
}

DataSourceNameParams defines the parameters required to construct a database connection string.

type DatabaseTLSConfig

type DatabaseTLSConfig struct {
	Mode       string `mapstructure:"mode"`
	CACertPath string `mapstructure:"ca-cert-path"`
}

DatabaseTLSConfig holds the database TLS mode and its necessary credentials.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL