Skip to content

Commit

Permalink
Retry initial connection
Browse files Browse the repository at this point in the history
  • Loading branch information
naggingant committed Sep 29, 2021
1 parent b32065f commit 7ed68b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 12 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package amqp
import (
"fmt"
"context"
"time"
"sync"

"github.com/streadway/amqp"
Expand Down Expand Up @@ -49,7 +50,17 @@ func (f backendFactory) New(remote *config.Backend) proxy.Proxy {
}

func (f backendFactory) newChannel(path string) (*amqp.Channel, closer, error) {
conn, err := amqp.Dial(path)
var (
conn *amqp.Connection
err error
)
for {
conn, err = amqp.Dial(path)
if err == nil {
break
}
time.Sleep(time.Duration(3) * time.Second)
}
if err != nil {
return nil, nopCloser, err
}
Expand Down
7 changes: 2 additions & 5 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,8 @@ func (f backendFactory) initRpcChannel(ctx context.Context, cfg *rpcCfg, dns str
if !ok {
break
}
for {
time.Sleep(time.Duration(3) * time.Second)
if err := f.initRpcChannel(ctx, cfg, dns, rch); err == nil {
break
}
if err := f.initRpcChannel(ctx, cfg, dns, rch); err == nil {
break
}
case reply, ok := <-replies:
if !ok {
Expand Down

0 comments on commit 7ed68b8

Please sign in to comment.