Skip to content

Commit

Permalink
Merge pull request #9 from itshikanov/master
Browse files Browse the repository at this point in the history
Add read/write timeout for master_resolver(redisMasterFromSentinelAddr)
  • Loading branch information
marriva authored Dec 23, 2024
2 parents c4fbce2 + 3afab1b commit 8e55241
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
flag.Parse()

if err := runProxying(localAddr, sentinelAddr, masterName, masterResolveRetries); err != nil {
log.Fatalln(err)
log.Fatalf("Fatal: %s", err)
}
log.Println("Exiting...")
}
Expand All @@ -47,14 +47,13 @@ func runProxying(localAddr, sentinelAddr, masterName string, masterResolveRetrie
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error { return masterAddrResolver.UpdateMasterAddressLoop(ctx) })
eg.Go(func() error { return rsp.Run(ctx) })

return eg.Wait()
}

func resolveTCPAddr(addr string) *net.TCPAddr {
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
if err != nil {
log.Fatalf("Failed resolving tcp address: %s", err)
log.Fatalf("Fatal - Failed resolving tcp address: %s", err)
}
return tcpAddr
}
1 change: 1 addition & 0 deletions pkg/master_resolver/master_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (r *RedisMasterResolver) initialMasterAdressResolve() error {

func redisMasterFromSentinelAddr(sentinelAddress *net.TCPAddr, masterName string) (*net.TCPAddr, error) {
conn, err := utils.TCPConnectWithTimeout(sentinelAddress.String())
conn.SetDeadline(time.Now().Add(time.Second))
if err != nil {
return nil, fmt.Errorf("error connecting to sentinel: %w", err)
}
Expand Down

0 comments on commit 8e55241

Please sign in to comment.