reconnect on 'the database system is starting up'
this is one reason bin-docker-testflight would hang
@@ -65,7 +65,7 @@ func Open(logger lager.Logger, sqlDriver string, sqlDataSource string, newKey *e
sqlDb, err := migration.NewOpenHelper(sqlDriver, sqlDataSource, lockFactory, strategy).Open()
if err != nil {
- if strings.Contains(err.Error(), "dial ") {
+ if shouldRetry(err) {
logger.Error("failed-to-open-db-retrying", err)
time.Sleep(5 * time.Second)
continue
@@ -103,6 +103,18 @@ func Open(logger lager.Logger, sqlDriver string, sqlDataSource string, newKey *e
}
}
+func shouldRetry(err error) bool {
+ if strings.Contains(err.Error(), "dial ") {
+ return true
+ }
+
+ if pqErr, ok := err.(*pq.Error); ok {
+ return pqErr.Code.Name() == "cannot_connect_now"
+ }
+
+ return false
+}
+
var encryptedColumns = map[string]string{
"teams": "auth",
"resources": "config",
