From d14917c95df121e9cd267ae87598edcc4e43c498 Mon Sep 17 00:00:00 2001 From: Fusl Date: Mon, 2 May 2022 09:43:43 +0000 Subject: [PATCH] dont close the channel when we're done, avoids lock congestion --- main.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index f46d93b..49c51ad 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,7 @@ type ProjectBackfeedManager struct { BackfeedRedis *redis.ClusterClient ProjectRedis *redis.Client LegacyRedis *redis.Client - Lock sync.RWMutex + //Lock sync.RWMutex ProjectConfig ProjectConfig } @@ -66,11 +66,11 @@ func (that *ProjectBackfeedManager) RedisConfigDiffers(new *ProjectRedisConfig) } func (that *ProjectBackfeedManager) PushItem(ctx context.Context, item *BackfeedItem) bool { - that.Lock.RLock() - defer that.Lock.RUnlock() - if that.C == nil { - return false - } + //that.Lock.RLock() + //defer that.Lock.RUnlock() + //if that.C == nil { + // return false + //} select { case <-ctx.Done(): return false @@ -101,19 +101,20 @@ func (that *ProjectBackfeedManager) PopItem(blocking bool) (*BackfeedItem, bool) } } -func (that *ProjectBackfeedManager) CloseItemChannel() { - that.Lock.Lock() - defer that.Lock.Unlock() - if that.C == nil { - return - } - close(that.C) - that.C = nil -} +//func (that *ProjectBackfeedManager) CloseItemChannel() { +// log.Printf("closing item channel for %s", that.Name) +// that.Lock.Lock() +// defer that.Lock.Unlock() +// if that.C == nil { +// return +// } +// close(that.C) +// that.C = nil +//} func (that *ProjectBackfeedManager) Do() { defer close(that.Done) - defer that.CloseItemChannel() + //defer that.CloseItemChannel() defer that.Cancel() for {