diff --git a/apps/wakunode2/app.nim b/apps/wakunode2/app.nim index 080700c3e..e72c474d4 100644 --- a/apps/wakunode2/app.nim +++ b/apps/wakunode2/app.nim @@ -410,10 +410,17 @@ proc setupProtocols(node: WakuNode, return err("failed to mount waku RLN relay protocol: " & getCurrentExceptionMsg()) if conf.store: + var onErrAction = proc(msg: string) {.gcsafe, closure.} = + ## Action to be taken when an internal error occurs during the node run. + ## e.g. the connection with the database is lost and not recovered. + error "Unrecoverable error occurred", error = msg + quit(QuitFailure) + # Archive setup let archiveDriverRes = ArchiveDriver.new(conf.storeMessageDbUrl, conf.storeMessageDbVacuum, - conf.storeMessageDbMigration) + conf.storeMessageDbMigration, + onErrAction) if archiveDriverRes.isErr(): return err("failed to setup archive driver: " & archiveDriverRes.error) diff --git a/waku/common/databases/db_postgres/pgasyncpool.nim b/waku/common/databases/db_postgres/pgasyncpool.nim index dc1104b3c..2e5fa4e07 100644 --- a/waku/common/databases/db_postgres/pgasyncpool.nim +++ b/waku/common/databases/db_postgres/pgasyncpool.nim @@ -136,6 +136,20 @@ proc getConnIndex(pool: PgAsyncPool): pool.conns[index].busy = true return ok(index) +proc resetConnPool*(pool: PgAsyncPool): Future[DatabaseResult[void]] {.async.} = + ## Forces closing the connection pool. + ## This proc is intended to be called when the connection with the database + ## got interrupted from the database side or a connectivity problem happened. + + for i in 0..