The people demand defers
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
parent
047f3948c5
commit
4de7a2fc9d
|
|
@ -177,8 +177,8 @@ func (a *AzureServiceBusQueues) Invoke(invokeCtx context.Context, req *bindings.
|
||||||
|
|
||||||
// Send the message
|
// Send the message
|
||||||
ctx, cancel := context.WithTimeout(invokeCtx, a.timeout)
|
ctx, cancel := context.WithTimeout(invokeCtx, a.timeout)
|
||||||
|
defer cancel()
|
||||||
err = sender.SendMessage(ctx, msg, nil)
|
err = sender.SendMessage(ctx, msg, nil)
|
||||||
cancel()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if impl.IsNetworkError(err) {
|
if impl.IsNetworkError(err) {
|
||||||
// Force reconnection on next call
|
// 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
|
// Acquire a write lock then try checking a.sender again in case another goroutine modified that in the meanwhile
|
||||||
a.senderLock.Lock()
|
a.senderLock.Lock()
|
||||||
|
defer a.senderLock.Unlock()
|
||||||
|
|
||||||
if a.sender != nil {
|
if a.sender != nil {
|
||||||
a.senderLock.Unlock()
|
|
||||||
return a.sender, nil
|
return a.sender, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new sender
|
// Create a new sender
|
||||||
sender, err := a.client.NewSender(a.metadata.QueueName, nil)
|
sender, err := a.client.NewSender(a.metadata.QueueName, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.senderLock.Unlock()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
a.sender = sender
|
a.sender = sender
|
||||||
a.senderLock.Unlock()
|
|
||||||
|
|
||||||
return sender, nil
|
return sender, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -329,8 +329,8 @@ func (a *azureServiceBus) Publish(req *pubsub.PublishRequest) error {
|
||||||
|
|
||||||
// Try sending the message
|
// Try sending the message
|
||||||
ctx, cancel := context.WithTimeout(a.publishCtx, time.Second*time.Duration(a.metadata.TimeoutInSec))
|
ctx, cancel := context.WithTimeout(a.publishCtx, time.Second*time.Duration(a.metadata.TimeoutInSec))
|
||||||
|
defer cancel()
|
||||||
err = sender.SendMessage(ctx, msg, nil)
|
err = sender.SendMessage(ctx, msg, nil)
|
||||||
cancel()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if impl.IsNetworkError(err) {
|
if impl.IsNetworkError(err) {
|
||||||
// Retry after reconnecting
|
// Retry after reconnecting
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue