@@ -2,6 +2,7 @@ package push
2
2
3
3
import (
4
4
"context"
5
+ "time"
5
6
6
7
"github.com/redis/go-redis/v9/internal"
7
8
"github.com/redis/go-redis/v9/internal/proto"
@@ -51,8 +52,19 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx
51
52
if rd == nil {
52
53
return nil
53
54
}
55
+ conn := handlerCtx .Conn
56
+ if conn == nil {
57
+ return nil
58
+ }
59
+ netConn := handlerCtx .Conn .GetNetConn ()
60
+ if netConn == nil {
61
+ return nil
62
+ }
54
63
55
64
for {
65
+ // Set a short read deadline to check for available data
66
+ // otherwise we may block on Peek if there is no data available
67
+ netConn .SetReadDeadline (time .Now ().Add (1 ))
56
68
// Check if there's data available to read
57
69
replyType , err := rd .PeekReplyType ()
58
70
if err != nil {
@@ -104,6 +116,7 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx
104
116
}
105
117
}
106
118
119
+ netConn .SetReadDeadline (time.Time {})
107
120
return nil
108
121
}
109
122
@@ -133,12 +146,23 @@ func (v *VoidProcessor) UnregisterHandler(pushNotificationName string) error {
133
146
// ProcessPendingNotifications for VoidProcessor does nothing since push notifications
134
147
// are only available in RESP3 and this processor is used for RESP2 connections.
135
148
// This avoids unnecessary buffer scanning overhead.
136
- func (v * VoidProcessor ) ProcessPendingNotifications (_ context.Context , _ NotificationHandlerContext , rd * proto.Reader ) error {
149
+ func (v * VoidProcessor ) ProcessPendingNotifications (_ context.Context , handlerCtx NotificationHandlerContext , rd * proto.Reader ) error {
137
150
// read and discard all push notifications
138
151
if rd == nil {
139
152
return nil
140
153
}
154
+ conn := handlerCtx .Conn
155
+ if conn == nil {
156
+ return nil
157
+ }
158
+ netConn := handlerCtx .Conn .GetNetConn ()
159
+ if netConn == nil {
160
+ return nil
161
+ }
141
162
for {
163
+ // Set a short read deadline to check for available data
164
+ netConn .SetReadDeadline (time .Now ().Add (1 ))
165
+ // Check if there's data available to read
142
166
replyType , err := rd .PeekReplyType ()
143
167
if err != nil {
144
168
// No more data available or error reading
@@ -166,6 +190,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, _ Notific
166
190
return nil
167
191
}
168
192
}
193
+ netConn .SetReadDeadline (time.Time {})
169
194
return nil
170
195
}
171
196
@@ -174,7 +199,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, _ Notific
174
199
func willHandleNotificationInClient (notificationType string ) bool {
175
200
switch notificationType {
176
201
// Pub/Sub notifications - handled by pub/sub system
177
- case "message" , // Regular pub/sub message
202
+ case "message" , // Regular pub/sub message
178
203
"pmessage" , // Pattern pub/sub message
179
204
"subscribe" , // Subscription confirmation
180
205
"unsubscribe" , // Unsubscription confirmation
0 commit comments