From 44dda6307424901f6d87cde68f4cb039766da3af Mon Sep 17 00:00:00 2001 From: shawnw Date: Sun, 5 Jan 2025 10:18:33 -0800 Subject: [PATCH] reproduce race --- osscluster.go | 5 +++-- race_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/osscluster.go b/osscluster.go index 72e922a..6e35bc7 100644 --- a/osscluster.go +++ b/osscluster.go @@ -685,7 +685,8 @@ func newClusterState( sort.Sort(clusterSlotSlice(c.slots)) - time.AfterFunc(time.Minute, func() { + // a minute originally + time.AfterFunc(1*time.Millisecond, func() { nodes.GC(c.generation) }) @@ -863,7 +864,7 @@ func (c *clusterStateHolder) LazyReload() { if err != nil { return } - time.Sleep(200 * time.Millisecond) + //time.Sleep(200 * time.Millisecond) }() } diff --git a/race_test.go b/race_test.go index aeb2d1f..8ef1988 100644 --- a/race_test.go +++ b/race_test.go @@ -2,6 +2,7 @@ package redis_test import ( "bytes" + "context" "fmt" "net" "strconv" @@ -312,6 +313,27 @@ var _ = Describe("cluster races", Label("NonRedisEnterprise"), func() { }) }) +var _ = FDescribe("cluster client internal races", Label("NonRedisEnterprise"), func() { + var client *redis.ClusterClient + + BeforeEach(func() { + opt := redisClusterOptions() + client = cluster.newClusterClient(ctx, opt) + }) + + It("should get addr", func() { + fmt.Println("start stressing") + testCtx, cancel := context.WithTimeout(ctx, 5 * time.Second) + defer cancel() + c := 10 + perform(c, func(id int) { + for testCtx.Err() == nil { + client.ReloadState(testCtx) + } + }) + }) +}) + func bigVal() []byte { return bytes.Repeat([]byte{'*'}, 1<<17) // 128kb } -- 2.39.2