@@ -126,7 +126,8 @@ func publisherRoutine(clientName string, channels []string, mode string, measure
126126 publishLatency := time .Now ().UnixNano () - startPublish
127127
128128 if err != nil {
129- log .Printf ("Error publishing to channel %s: %v" , ch , err )
129+ log .Printf ("Publisher %s: error publishing to channel %s: %v" , clientName , ch , err )
130+ // Don't send metrics on error, but still count the message attempt
130131 } else {
131132 // Send metrics to channels
132133 publishLatencyChannel <- publishLatency
@@ -218,11 +219,34 @@ func subscriberRoutine(clientName, mode string, channels []string, verbose bool,
218219 // Handle messages
219220 msg , err := pubsub .ReceiveMessage (ctx )
220221 if err != nil {
221- // Handle Redis connection errors, e.g., reconnect immediately
222+ // Handle Redis connection errors
222223 if err == redis .Nil || err == context .DeadlineExceeded || err == context .Canceled {
223224 continue
224225 }
225- panic (err )
226+ // Connection error (EOF, network error, etc.) - attempt to reconnect
227+ log .Printf ("Subscriber %s: connection error: %v - attempting to reconnect\n " , clientName , err )
228+
229+ // Close the bad connection
230+ if pubsub != nil {
231+ pubsub .Close ()
232+ atomic .AddInt64 (& totalSubscribedChannels , int64 (- len (channels )))
233+ }
234+
235+ // Wait a bit before reconnecting
236+ time .Sleep (100 * time .Millisecond )
237+
238+ // Resubscribe
239+ switch mode {
240+ case "ssubscribe" :
241+ pubsub = client .SSubscribe (ctx , channels ... )
242+ default :
243+ pubsub = client .Subscribe (ctx , channels ... )
244+ }
245+ atomic .AddInt64 (& totalSubscribedChannels , int64 (len (channels )))
246+ atomic .AddUint64 (& totalConnects , 1 )
247+
248+ log .Printf ("Subscriber %s: reconnected successfully\n " , clientName )
249+ continue
226250 }
227251 if verbose {
228252 log .Println (fmt .Sprintf ("received message in channel %s. Message: %s" , msg .Channel , msg .Payload ))
0 commit comments