mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
fix(channelserver): configure DB pool and add transactions for guild ops
sqlx.Open was called with no pool configuration, risking PostgreSQL connection exhaustion under load. Set max open/idle conns and lifetimes. CreatePost INSERT + soft-delete UPDATE were two separate queries with no transaction, risking inconsistent state on partial failure. CollectAdventure used SELECT then UPDATE without a lock, allowing concurrent guild members to double-collect. Now uses SELECT FOR UPDATE within a transaction.
This commit is contained in:
7
main.go
7
main.go
@@ -136,6 +136,13 @@ func main() {
|
||||
if err != nil {
|
||||
preventClose(config, fmt.Sprintf("Database: Failed to ping, %s", err.Error()))
|
||||
}
|
||||
|
||||
// Configure connection pool to avoid exhausting PostgreSQL under load.
|
||||
db.SetMaxOpenConns(50)
|
||||
db.SetMaxIdleConns(10)
|
||||
db.SetConnMaxLifetime(5 * time.Minute)
|
||||
db.SetConnMaxIdleTime(2 * time.Minute)
|
||||
|
||||
logger.Info("Database: Started successfully")
|
||||
|
||||
// Pre-compute all server IDs this instance will own, so we only
|
||||
|
||||
Reference in New Issue
Block a user