Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Issue #49 - Hopeful fix for stale connection issue
Supposedly setting the max conn lifetime will help
with the bad reads. Is something not reading completely?
  • Loading branch information
lfkeitel committed Jan 8, 2018
1 parent 31e89d7 commit ac2f5c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cmd/pg/main.go
Expand Up @@ -78,13 +78,6 @@ func main() {
common.SystemLogger = e.Log
e.Log.Debugf("Configuration loaded from %s", configFile)

c := e.SubscribeShutdown()
go func(e *common.Environment) {
<-c
e.Log.Notice("Shutting down...")
time.Sleep(2)
}(e)

e.DB, err = db.NewDatabaseAccessor(e)
if err != nil {
e.Log.WithField("error", err).Fatal("Error loading database")
Expand All @@ -94,6 +87,16 @@ func main() {
"address": e.Config.Database.Address,
}).Debug("Loaded database")

c := e.SubscribeShutdown()
go func(e *common.Environment) {
<-c
if err := e.DB.Close(); err != nil {
e.Log.Warningf("Error closing database: %s", err)
}
e.Log.Notice("Shutting down...")
time.Sleep(2)
}(e)

e.Sessions, err = common.NewSessionStore(e)
if err != nil {
e.Log.WithField("error", err).Fatal("Error loading session store")
Expand Down
1 change: 1 addition & 0 deletions src/db/databaseCommon.go
Expand Up @@ -63,6 +63,7 @@ func NewDatabaseAccessor(e *common.Environment) (*common.DatabaseAccessor, error
}
}

da.SetConnMaxLifetime(time.Minute)
return da, err
}
return nil, errors.New("Database " + e.Config.Database.Type + " not supported")
Expand Down

0 comments on commit ac2f5c9

Please sign in to comment.