Skip to content

Commit

Permalink
Fixing the handling of detach errors (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkedy authored Jul 23, 2021
1 parent bc5d716 commit f31b4e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 8 additions & 1 deletion pubsub/azure/servicebus/servicebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,14 @@ func (a *azureServiceBus) Subscribe(req pubsub.SubscribeRequest, handler pubsub.
a.metadata.MaxActiveMessages,
a.metadata.MaxActiveMessagesRecoveryInSec)
if innerErr != nil {
a.logger.Error(innerErr)
var detachError *amqp.DetachError
var ampqError *amqp.Error
if errors.Is(innerErr, detachError) ||
(errors.As(innerErr, &ampqError) && ampqError.Condition == amqp.ErrorDetachForced) {
a.logger.Debug(innerErr)
} else {
a.logger.Error(innerErr)
}
}
cancel() // Cancel receive context

Expand Down
7 changes: 1 addition & 6 deletions pubsub/azure/servicebus/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package servicebus
import (
"context"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -203,11 +202,7 @@ func (s *subscription) tryRenewLocks() {
func (s *subscription) receiveMessage(ctx context.Context, handler azservicebus.HandlerFunc) error {
s.logger.Debugf("Waiting to receive message on topic %s", s.topic)
if err := s.entity.ReceiveOne(ctx, handler); err != nil {
if strings.Contains(err.Error(), "force detached") {
return nil
}

return fmt.Errorf("%s error receiving message on topic %s, %s", errorMessagePrefix, s.topic, err)
return fmt.Errorf("%s error receiving message on topic %s, %w", errorMessagePrefix, s.topic, err)
}

return nil
Expand Down

0 comments on commit f31b4e4

Please sign in to comment.