Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions db_store/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func (cfg *DBConfig) AsDSN() string {
}

func (cfg *DBConfig) Validate() error {
_, err := sqlx.Connect("mysql", cfg.AsDSN())
return err
db, err := sqlx.Connect("mysql", cfg.AsDSN())
if err != nil {
return err
}
return db.Close()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the only fix that is needed. The others wouldn't have major effect, since there is a limit of 5 idle connections. But this one likely leaks a connection... everytime you reload. So I'd be willing to bet you are reloading often. I'm not sure why so often tho :). But this would also explain why I don't see the issue. I last restarted sometime in 2025 and pretty much never reload.

But I think this should be fixed differently, maybe. I'm not sure it makes sense to do a real test of the DB connection in config validation. This could probably just be an sqlx.Open, instead.

Sorry for the delay in seeing this.

}
3 changes: 3 additions & 0 deletions db_store/golbat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db_store

import (
"context"
"time"

"github.com/jmoiron/sqlx"
"github.com/paulmach/orb/geojson"
Expand Down Expand Up @@ -52,6 +53,8 @@ func NewGolbatDBStore(config DBConfig, logger *logrus.Logger) (*GolbatDBStore, e
}
db.SetMaxOpenConns(config.MaxPool)
db.SetMaxIdleConns(5)
db.SetConnMaxLifetime(5 * time.Minute)
db.SetConnMaxIdleTime(5 * time.Minute)

return &GolbatDBStore{
logger: logger,
Expand Down
3 changes: 3 additions & 0 deletions db_store/nests.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ func (st *NestsDBStore) Migrate(migratePath string) error {
if err != nil {
return fmt.Errorf("failed to connect to the DB: %w", err)
}
defer db.Close()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to clean this one up, also, tho it would just leak this 1 connection on startup.


dbDriver, err := migrate_mysql.WithInstance(db, migrateConfig)
if err != nil {
Expand Down Expand Up @@ -691,6 +692,8 @@ func NewNestsDBStore(config DBConfig, logger *logrus.Logger) (*NestsDBStore, err

db.SetMaxOpenConns(config.MaxPool)
db.SetMaxIdleConns(5)
db.SetConnMaxLifetime(5 * time.Minute)
db.SetConnMaxIdleTime(5 * time.Minute)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not really any reason for the max lifetime one. The max idle time seems reasonable. You only save 5 connections tho.


return &NestsDBStore{
logger: logger,
Expand Down