fix: harden Redis client timeouts and correct userid column bugs
Redis client had a 35s worst-case stall (10s read/write timeout x3 retries) on a single call, which under concurrent load exhausted the connection pool and cascaded into a full outage. Timeouts and retries are now tight enough that a degraded Redis fails fast instead of tying up pooled connections. Also fixes two userid/appuserid column mix-ups in delivery queries (deliveryController.go, domain/delivery.go) and points the Dockerfile build at main.go explicitly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ FROM golang:1.24
|
|||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
ADD . /app/
|
ADD . /app/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server .
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server main.go
|
||||||
|
|
||||||
# Second Stage
|
# Second Stage
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|||||||
@@ -709,7 +709,7 @@ func GetDeliverySummary(c *fiber.Ctx) error {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
if appuid != 0 {
|
if appuid != 0 {
|
||||||
qb.WriteString(" AND g.userid = ?")
|
qb.WriteString(" AND a.userid = ?")
|
||||||
params = append(params, appuid)
|
params = append(params, appuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,18 +183,23 @@ func InitRedis() {
|
|||||||
DB: 0,
|
DB: 0,
|
||||||
|
|
||||||
// ✅ TIMEOUTS (VERY IMPORTANT)
|
// ✅ TIMEOUTS (VERY IMPORTANT)
|
||||||
DialTimeout: 10 * time.Second,
|
// Kept short so a slow/degraded Redis fails fast instead of tying up a
|
||||||
ReadTimeout: 10 * time.Second,
|
// pooled connection for tens of seconds. A previous config (10s x3 retries)
|
||||||
WriteTimeout: 10 * time.Second,
|
// let a single stuck call hold a connection for ~35s, which under concurrent
|
||||||
|
// load exhausted the pool and cascaded into a cluster-wide outage.
|
||||||
|
DialTimeout: 5 * time.Second,
|
||||||
|
ReadTimeout: 3 * time.Second,
|
||||||
|
WriteTimeout: 3 * time.Second,
|
||||||
|
|
||||||
// ✅ POOL
|
// ✅ POOL
|
||||||
PoolSize: 50,
|
PoolSize: 50,
|
||||||
MinIdleConns: 10,
|
MinIdleConns: 10,
|
||||||
|
PoolTimeout: 4 * time.Second,
|
||||||
|
|
||||||
// ✅ RETRIES
|
// ✅ RETRIES
|
||||||
MaxRetries: 3,
|
MaxRetries: 1,
|
||||||
MinRetryBackoff: 500 * time.Millisecond,
|
MinRetryBackoff: 100 * time.Millisecond,
|
||||||
MaxRetryBackoff: 2 * time.Second,
|
MaxRetryBackoff: 500 * time.Millisecond,
|
||||||
})
|
})
|
||||||
|
|
||||||
maxRetries := 5
|
maxRetries := 5
|
||||||
|
|||||||
@@ -792,7 +792,7 @@ func GetUserDeliveriesv1(input models.DeliveryQuery) []models.Deliveryinfo {
|
|||||||
func GetAppUserDeliveries(input models.DeliveryQuery) []models.Deliveryinfo {
|
func GetAppUserDeliveries(input models.DeliveryQuery) []models.Deliveryinfo {
|
||||||
var data []models.Deliveryinfo
|
var data []models.Deliveryinfo
|
||||||
|
|
||||||
logInfo("App User Deliveries", "appuserid", input.UserID)
|
logInfo("App User Deliveries", "appuserid", input.Appuserid)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
q1 strings.Builder
|
q1 strings.Builder
|
||||||
@@ -805,10 +805,10 @@ func GetAppUserDeliveries(input models.DeliveryQuery) []models.Deliveryinfo {
|
|||||||
q1.WriteString(deliveries)
|
q1.WriteString(deliveries)
|
||||||
q1.WriteString(" WHERE b.moduleid = 6 AND g.status = 'Active' ")
|
q1.WriteString(" WHERE b.moduleid = 6 AND g.status = 'Active' ")
|
||||||
|
|
||||||
// 🔹 Apply userid filter ONLY if userid > 0
|
// 🔹 Apply appuserid filter ONLY if appuserid > 0
|
||||||
if input.UserID > 0 {
|
if input.Appuserid > 0 {
|
||||||
q1.WriteString(" AND g.userid = ? ")
|
q1.WriteString(" AND a.userid = ? ")
|
||||||
params = append(params, input.UserID)
|
params = append(params, input.Appuserid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔹 Status filter (IGNORE if status = all)
|
// 🔹 Status filter (IGNORE if status = all)
|
||||||
|
|||||||
Reference in New Issue
Block a user