Skip to content

Commit 4e35707

Browse files
committed
fix: add nil reader check in ProcessPendingNotifications to prevent panic
- Add nil check for proto.Reader parameter in both PushNotificationProcessor and VoidPushNotificationProcessor - Prevent segmentation violation when ProcessPendingNotifications is called with nil reader - Return early with nil error when reader is nil (graceful handling) - Fix panic in TestProcessPendingNotificationsEdgeCases test This addresses the runtime panic that occurred when rd.Buffered() was called on a nil reader, ensuring robust error handling in edge cases where the reader might not be properly initialized.
1 parent 03bfd9f commit 4e35707

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

push_notifications.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ func (p *PushNotificationProcessor) GetRegistryForTesting() *PushNotificationReg
142142

143143
// ProcessPendingNotifications checks for and processes any pending push notifications.
144144
func (p *PushNotificationProcessor) ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error {
145+
// Check for nil reader
146+
if rd == nil {
147+
return nil
148+
}
145149

146150
// Check if there are any buffered bytes that might contain push notifications
147151
if rd.Buffered() == 0 {
@@ -255,6 +259,11 @@ func (v *VoidPushNotificationProcessor) GetRegistryForTesting() *PushNotificatio
255259

256260
// ProcessPendingNotifications reads and discards any pending push notifications.
257261
func (v *VoidPushNotificationProcessor) ProcessPendingNotifications(ctx context.Context, rd *proto.Reader) error {
262+
// Check for nil reader
263+
if rd == nil {
264+
return nil
265+
}
266+
258267
// Read and discard any pending push notifications to clean the buffer
259268
for {
260269
// Peek at the next reply type to see if it's a push notification

0 commit comments

Comments
 (0)