Permalink
Browse files

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 ac2f5c984a260bccc9cbf35f60288536cd2beaff
Showing with 11 additions and 7 deletions.
  1. +10 −7 cmd/pg/main.go
  2. +1 −0 src/db/databaseCommon.go
@@ -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")
@@ -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")
@@ -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")

0 comments on commit ac2f5c9

Please sign in to comment.