Skip to content

Commit d1d4529

Browse files
committed
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.
1 parent 8006fab commit d1d4529

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sentinel.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,14 @@ func NewSentinelClient(opt *Options) *SentinelClient {
492492
},
493493
}
494494

495+
// Initialize push notification processor to prevent nil pointer dereference
496+
if opt.PushNotificationProcessor != nil {
497+
c.pushProcessor = opt.PushNotificationProcessor
498+
} else {
499+
// Create void processor for Sentinel (typically doesn't need push notifications)
500+
c.pushProcessor = NewVoidPushNotificationProcessor()
501+
}
502+
495503
c.initHooks(hooks{
496504
dial: c.baseClient.dial,
497505
process: c.baseClient.process,
@@ -501,6 +509,18 @@ func NewSentinelClient(opt *Options) *SentinelClient {
501509
return c
502510
}
503511

512+
// GetPushNotificationProcessor returns the push notification processor.
513+
func (c *SentinelClient) GetPushNotificationProcessor() PushNotificationProcessorInterface {
514+
return c.pushProcessor
515+
}
516+
517+
// RegisterPushNotificationHandler registers a handler for a specific push notification name.
518+
// Returns an error if a handler is already registered for this push notification name.
519+
// If protected is true, the handler cannot be unregistered.
520+
func (c *SentinelClient) RegisterPushNotificationHandler(pushNotificationName string, handler PushNotificationHandler, protected bool) error {
521+
return c.pushProcessor.RegisterHandler(pushNotificationName, handler, protected)
522+
}
523+
504524
func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error {
505525
err := c.processHook(ctx, cmd)
506526
cmd.SetErr(err)

0 commit comments

Comments
 (0)