@@ -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,23 @@ 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
+ err := netConn .SetReadDeadline (time .Now ().Add (1 ))
68
+ if err != nil {
69
+ return err
70
+ }
71
+
56
72
// Check if there's data available to read
57
73
replyType , err := rd .PeekReplyType ()
58
74
if err != nil {
@@ -104,7 +120,7 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx
104
120
}
105
121
}
106
122
107
- return nil
123
+ return netConn . SetReadDeadline (time. Time {})
108
124
}
109
125
110
126
// VoidProcessor discards all push notifications without processing them
@@ -133,12 +149,26 @@ func (v *VoidProcessor) UnregisterHandler(pushNotificationName string) error {
133
149
// ProcessPendingNotifications for VoidProcessor does nothing since push notifications
134
150
// are only available in RESP3 and this processor is used for RESP2 connections.
135
151
// This avoids unnecessary buffer scanning overhead.
136
- func (v * VoidProcessor ) ProcessPendingNotifications (_ context.Context , _ NotificationHandlerContext , rd * proto.Reader ) error {
152
+ func (v * VoidProcessor ) ProcessPendingNotifications (_ context.Context , handlerCtx NotificationHandlerContext , rd * proto.Reader ) error {
137
153
// read and discard all push notifications
138
154
if rd == nil {
139
155
return nil
140
156
}
157
+ conn := handlerCtx .Conn
158
+ if conn == nil {
159
+ return nil
160
+ }
161
+ netConn := handlerCtx .Conn .GetNetConn ()
162
+ if netConn == nil {
163
+ return nil
164
+ }
141
165
for {
166
+ // Set a short read deadline to check for available data
167
+ err := netConn .SetReadDeadline (time .Now ().Add (1 ))
168
+ if err != nil {
169
+ return err
170
+ }
171
+ // Check if there's data available to read
142
172
replyType , err := rd .PeekReplyType ()
143
173
if err != nil {
144
174
// No more data available or error reading
@@ -166,7 +196,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, _ Notific
166
196
return nil
167
197
}
168
198
}
169
- return nil
199
+ return netConn . SetReadDeadline (time. Time {})
170
200
}
171
201
172
202
// willHandleNotificationInClient checks if a notification type should be ignored by the push notification
0 commit comments