have lru.Get() always check if context is already expired

This commit is contained in:
Georges Varouchas 2021-11-08 21:00:24 +01:00 committed by Jack Christensen
parent 141f132ae7
commit cd7dcd5802

View File

@ -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