Skip to content

Commit c31ec64

Browse files
committed
check err on requeue
1 parent 0fd9871 commit c31ec64

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

hitless/pool_hook.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -274,26 +274,33 @@ func (ph *PoolHook) processHandoffRequest(request HandoffRequest) {
274274

275275
internal.Logger.Printf(context.Background(), "Handoff failed for connection WILL RETRY After %v: %v", afterTime, err)
276276
time.AfterFunc(afterTime, func() {
277-
ph.queueHandoff(request.Conn)
277+
if err := ph.queueHandoff(request.Conn); err != nil {
278+
internal.Logger.Printf(context.Background(), "can't queue handoff for retry: %v", err)
279+
ph.removeConn(ctx, request, err)
280+
}
278281
})
279282
} else {
280-
pooler := request.Pool
281-
conn := request.Conn
282-
if pooler != nil {
283-
go pooler.Remove(ctx, conn, err)
284-
if ph.config != nil && ph.config.LogLevel >= 1 { // Warning level
285-
internal.Logger.Printf(ctx,
286-
"hitless: removed connection %d from pool due to max handoff retries reached",
287-
conn.GetID())
288-
}
289-
} else {
290-
go conn.Close()
291-
if ph.config != nil && ph.config.LogLevel >= 1 { // Warning level
292-
internal.Logger.Printf(ctx,
293-
"hitless: no pool provided for connection %d, cannot remove due to handoff initialization failure: %v",
294-
conn.GetID(), err)
295-
}
296-
}
283+
go ph.removeConn(ctx, request, err)
284+
}
285+
}
286+
}
287+
288+
func (ph *PoolHook) removeConn(ctx context.Context, request HandoffRequest, err error) {
289+
pooler := request.Pool
290+
conn := request.Conn
291+
if pooler != nil {
292+
pooler.Remove(ctx, conn, err)
293+
if ph.config != nil && ph.config.LogLevel >= 1 { // Warning level
294+
internal.Logger.Printf(ctx,
295+
"hitless: removed connection %d from pool due to max handoff retries reached",
296+
conn.GetID())
297+
}
298+
} else {
299+
conn.Close()
300+
if ph.config != nil && ph.config.LogLevel >= 1 { // Warning level
301+
internal.Logger.Printf(ctx,
302+
"hitless: no pool provided for connection %d, cannot remove due to handoff initialization failure: %v",
303+
conn.GetID(), err)
297304
}
298305
}
299306
}

0 commit comments

Comments
 (0)