The recommended lazy database initialization example discards errors and prevents retry
Source references: 2Inside sync.Once, the example discards the error from sql.Open with an underscore and then returns db.conn unconditionally. Because Once runs only once, a failed first initialization is never attempted again.
If an agent copies this into real database code, driver, configuration, or initialization errors may be hidden. Callers can receive a nil or unusable connection, causing later failures or service outage while preventing automatic recovery.
This is instructional sample code, not automatically executed behavior, but the risk applies if a user adopts it. sync.Once runs the initializer only once, while the sql.Open error is discarded with `_`; callers cannot detect initialization failure or trigger a retry and may receive a nil or unusable connection. A user can ask the author for an example that returns `(*sql.DB, error)`, preserves and checks the initialization error, and defines an explicit retry policy.
10. **Design useful zero values** — nil map fields panic on first write; use lazy init11. **Use `sync.Once` for lazy init** — guarantees exactly-once even under concurrencyShow 1 other places
func (db *DB) connection() *sql.DB { db.once.Do(func() { db.conn, _ = sql.Open("postgres", connStr) }) return db.conn}```