From f1e7dc4056abaa6549bf014d2e6b67508437d236 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Tue, 3 Dec 2024 10:27:50 +0300 Subject: [PATCH] fix: closing the Client also closes the broker * The error was also previously unhandled. For shared connections an error will be returned by the broker itself because the sharedConnection bool is also set on the client. This also means we can get rid of the sharedConnection flag on the Scheduler itself and let it work internally. --- scheduler.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scheduler.go b/scheduler.go index 5226a3b..9dbfa1b 100644 --- a/scheduler.go +++ b/scheduler.go @@ -44,9 +44,6 @@ type Scheduler struct { // to avoid using cron.EntryID as the public API of // the Scheduler. idmap map[string]cron.EntryID - // When a Scheduler has been created with an existing Redis connection, we do - // not want to close it. - sharedConnection bool } const defaultHeartbeatInterval = 10 * time.Second @@ -65,7 +62,6 @@ func NewScheduler(r RedisConnOpt, opts *SchedulerOpts) *Scheduler { scheduler.rdb = rdb scheduler.client = &Client{broker: rdb, sharedConnection: false} - scheduler.sharedConnection = false return scheduler } @@ -78,7 +74,6 @@ func NewSchedulerFromRedisClient(c redis.UniversalClient, opts *SchedulerOpts) * scheduler.rdb = rdb.NewRDB(c) scheduler.client = NewClientFromRedisClient(c) - scheduler.sharedConnection = true return scheduler } @@ -309,9 +304,6 @@ func (s *Scheduler) Shutdown() { if err := s.client.Close(); err != nil { s.logger.Errorf("Failed to close redis client connection: %v", err) } - if !s.sharedConnection { - s.rdb.Close() - } s.logger.Info("Scheduler stopped") }