From cd7dcd58025f5936f76170cf8d9d2fa467b3c189 Mon Sep 17 00:00:00 2001 From: Georges Varouchas Date: Mon, 8 Nov 2021 21:00:24 +0100 Subject: [PATCH] have lru.Get() always check if context is already expired --- stmtcache/lru.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stmtcache/lru.go b/stmtcache/lru.go index f58f2ac3..a4106457 100644 --- a/stmtcache/lru.go +++ b/stmtcache/lru.go @@ -53,6 +53,14 @@ func (c *LRU) Get(ctx context.Context, sql string) (*pgconn.StatementDescription } } + if ctx != context.Background() { + select { + case <-ctx.Done(): + return nil, ctx.Err() + default: + } + } + if el, ok := c.m[sql]; ok { c.l.MoveToFront(el) return el.Value.(*pgconn.StatementDescription), nil