@@ -229,7 +229,7 @@ func (p *Amqp10Publisher) SendAsync(ctx context.Context) error {
229
229
case <- ctx .Done ():
230
230
return nil
231
231
default :
232
- err = p .handleSendErrors (err )
232
+ err = p .handleSendErrors (ctx , err )
233
233
if err != nil {
234
234
return err
235
235
}
@@ -249,7 +249,7 @@ func (p *Amqp10Publisher) SendSync(ctx context.Context) error {
249
249
err := p .Sender .Send (context .TODO (), msg , nil )
250
250
latency := time .Since (startTime )
251
251
log .Debug ("message sent" , "id" , p .Id , "destination" , p .Terminus , "latency" , latency , "appProps" , msg .ApplicationProperties )
252
- err = p .handleSendErrors (err )
252
+ err = p .handleSendErrors (ctx , err )
253
253
if err != nil {
254
254
return err
255
255
}
@@ -262,19 +262,29 @@ func (p *Amqp10Publisher) SendSync(ctx context.Context) error {
262
262
// handleSendErrors returns an error if the error suggests we should reconnect
263
263
// (this is native, but amqp-go-client should handle this better in the future)
264
264
// otherwise we log an error but return nil to keep publishing
265
- func (p * Amqp10Publisher ) handleSendErrors (err error ) error {
266
- var connErr * amqp.ConnError
267
- var linkErr * amqp.LinkError
268
- if errors .As (err , & connErr ) {
269
- log .Error ("publisher connection failure; reconnecting..." , "id" , p .Id , "error" , connErr .Error ())
270
- return err
271
- } else if errors .As (err , & linkErr ) {
272
- log .Error ("publisher link failure; reconnecting..." , "id" , p .Id , "error" , connErr .Error ())
273
- return err
274
- } else if err != nil {
275
- log .Error ("message sending failure" , "id" , p .Id , "error" , err )
265
+ func (p * Amqp10Publisher ) handleSendErrors (ctx context.Context , err error ) error {
266
+ select {
267
+ case <- ctx .Done ():
268
+ return nil
269
+ default :
270
+ var connErr * amqp.ConnError
271
+ var linkErr * amqp.LinkError
272
+ if errors .As (err , & connErr ) {
273
+ log .Error ("publisher connection failure; reconnecting..." , "id" , p .Id , "error" , connErr .Error ())
274
+ return err
275
+ }
276
+
277
+ if errors .As (err , & linkErr ) {
278
+ log .Error ("publisher link failure; reconnecting..." , "id" , p .Id , "error" , connErr .Error ())
279
+ return err
280
+ }
281
+
282
+ if err != nil {
283
+ log .Error ("message sending failure" , "id" , p .Id , "error" , err )
284
+ }
285
+
286
+ return nil
276
287
}
277
- return nil
278
288
}
279
289
280
290
func (p * Amqp10Publisher ) handleSent (receipt * amqp.SendReceipt , published time.Time ) {
0 commit comments