From 90a7e2da1f120e8a873e7fdcd802b50d232fe9e2 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 20 Jul 2022 13:40:52 +0300 Subject: [PATCH] cancel context for app.close --- util/ocache/ocache.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/ocache/ocache.go b/util/ocache/ocache.go index bee93cc27..16cbb49e6 100644 --- a/util/ocache/ocache.go +++ b/util/ocache/ocache.go @@ -78,6 +78,7 @@ type entry struct { load chan struct{} loadErr error value Object + cancel func() } type OCache interface { @@ -142,6 +143,7 @@ func (c *oCache) Get(ctx context.Context, id string) (value Object, err error) { id: id, load: make(chan struct{}), } + ctx, e.cancel = context.WithCancel(ctx) c.data[id] = e } e.lastUsage = c.timeNow() @@ -358,6 +360,9 @@ func (c *oCache) Close() (err error) { } c.mu.Unlock() for _, e := range toClose { + if e.cancel != nil { + e.cancel() + } <-e.load if e.value != nil { if clErr := e.value.Close(); clErr != nil {