The people demand defers

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
ItalyPaleAle 2022-10-12 18:46:38 +00:00
parent 047f3948c5
commit 4de7a2fc9d
2 changed files with 3 additions and 5 deletions

View File

@ -177,8 +177,8 @@ func (a *AzureServiceBusQueues) Invoke(invokeCtx context.Context, req *bindings.
// Send the message
ctx, cancel := context.WithTimeout(invokeCtx, a.timeout)
defer cancel()
err = sender.SendMessage(ctx, msg, nil)
cancel()
if err != nil {
if impl.IsNetworkError(err) {
// Force reconnection on next call
@ -269,20 +269,18 @@ func (a *AzureServiceBusQueues) getSender() (*servicebus.Sender, error) {
// Acquire a write lock then try checking a.sender again in case another goroutine modified that in the meanwhile
a.senderLock.Lock()
defer a.senderLock.Unlock()
if a.sender != nil {
a.senderLock.Unlock()
return a.sender, nil
}
// Create a new sender
sender, err := a.client.NewSender(a.metadata.QueueName, nil)
if err != nil {
a.senderLock.Unlock()
return nil, err
}
a.sender = sender
a.senderLock.Unlock()
return sender, nil
}

View File

@ -329,8 +329,8 @@ func (a *azureServiceBus) Publish(req *pubsub.PublishRequest) error {
// Try sending the message
ctx, cancel := context.WithTimeout(a.publishCtx, time.Second*time.Duration(a.metadata.TimeoutInSec))
defer cancel()
err = sender.SendMessage(ctx, msg, nil)
cancel()
if err != nil {
if impl.IsNetworkError(err) {
// Retry after reconnecting