From d1d4529abfad264102b37dcdab00eae569dc6abe Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Fri, 27 Jun 2025 01:44:38 +0300 Subject: [PATCH] fix: initialize push notification processor in SentinelClient - Add push processor initialization to NewSentinelClient to prevent nil pointer dereference - Add GetPushNotificationProcessor and RegisterPushNotificationHandler methods to SentinelClient - Use VoidPushNotificationProcessor for Sentinel (typically doesn't need push notifications) - Ensure consistent behavior across all client types that inherit from baseClient This fixes the panic that was occurring in Sentinel contexts where the pushProcessor field was nil, causing segmentation violations when processing commands. --- sentinel.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sentinel.go b/sentinel.go index 04c0f726..61494d72 100644 --- a/sentinel.go +++ b/sentinel.go @@ -492,6 +492,14 @@ func NewSentinelClient(opt *Options) *SentinelClient { }, } + // Initialize push notification processor to prevent nil pointer dereference + if opt.PushNotificationProcessor != nil { + c.pushProcessor = opt.PushNotificationProcessor + } else { + // Create void processor for Sentinel (typically doesn't need push notifications) + c.pushProcessor = NewVoidPushNotificationProcessor() + } + c.initHooks(hooks{ dial: c.baseClient.dial, process: c.baseClient.process, @@ -501,6 +509,18 @@ func NewSentinelClient(opt *Options) *SentinelClient { return c } +// GetPushNotificationProcessor returns the push notification processor. +func (c *SentinelClient) GetPushNotificationProcessor() PushNotificationProcessorInterface { + return c.pushProcessor +} + +// RegisterPushNotificationHandler registers a handler for a specific push notification name. +// Returns an error if a handler is already registered for this push notification name. +// If protected is true, the handler cannot be unregistered. +func (c *SentinelClient) RegisterPushNotificationHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error { + return c.pushProcessor.RegisterHandler(pushNotificationName, handler, protected) +} + func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error { err := c.processHook(ctx, cmd) cmd.SetErr(err)