-
-
Notifications
You must be signed in to change notification settings - Fork 941
Open
Labels
Description
Default driver do not implements DriverContext:
// Driver is the Postgres database driver.
type Driver struct{}
// Open opens a new connection to the database. name is a connection string.
// Most users should only use it through database/sql package from the standard
// library.
func (d Driver) Open(name string) (driver.Conn, error) {
return Open(name)
}
func init() {
sql.Register("postgres", &Driver{})
}
as a result, when src/database/sql/sql.go do
ci, err := db.connector.Connect(ctx)
it uses default connector which ignore context:
func Open(driverName, dataSourceName string) (*DB, error) {
driversMu.RLock()
driveri, ok := drivers[driverName]
driversMu.RUnlock()
if !ok {
return nil, fmt.Errorf("sql: unknown driver %q (forgotten import?)", driverName)
}
if driverCtx, ok := driveri.(driver.DriverContext); ok {
connector, err := driverCtx.OpenConnector(dataSourceName)
if err != nil {
return nil, err
}
return OpenDB(connector), nil
}
return OpenDB(dsnConnector{dsn: dataSourceName, driver: driveri}), nil
}
It results in connection hanging indefinitelly and leaking ports if database become unreachable during connection.
Reactions are currently unavailable