From f50e6ced719b8940f29b9611944cdedbbbfd0fb9 Mon Sep 17 00:00:00 2001 From: LightningTipBot <88730856+LightningTipBot@users.noreply.github.com> Date: Wed, 8 Dec 2021 22:22:11 +0100 Subject: [PATCH] test mutex (#158) Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com> --- internal/telegram/interceptor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/telegram/interceptor.go b/internal/telegram/interceptor.go index f48c5fa..3d2e96d 100644 --- a/internal/telegram/interceptor.go +++ b/internal/telegram/interceptor.go @@ -47,7 +47,9 @@ func (bot TipBot) unlockInterceptor(ctx context.Context, i interface{}) (context user := getTelegramUserFromInterface(i) if user != nil { handlerMapMutex.Lock() - handlerMutex[user.ID].Unlock() + if handlerMutex[user.ID] != nil { + handlerMutex[user.ID].Unlock() + } handlerMapMutex.Unlock() } return ctx, nil @@ -58,10 +60,10 @@ func (bot TipBot) lockInterceptor(ctx context.Context, i interface{}) (context.C user := getTelegramUserFromInterface(i) if user != nil { handlerMapMutex.Lock() - defer handlerMapMutex.Unlock() if handlerMutex[user.ID] == nil { handlerMutex[user.ID] = &sync.Mutex{} } + handlerMapMutex.Unlock() handlerMutex[user.ID].Lock() return ctx, nil }