Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #94 from libp2p/simplify-dial-context
Browse files Browse the repository at this point in the history
simplify dial timeout context
  • Loading branch information
marten-seemann authored Sep 19, 2021
2 parents a8f6d63 + 0e6e02b commit 649bdea
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ func (t *TcpTransport) CanDial(addr ma.Multiaddr) bool {
func (t *TcpTransport) maDial(ctx context.Context, raddr ma.Multiaddr) (manet.Conn, error) {
// Apply the deadline iff applicable
if t.ConnectTimeout > 0 {
deadline := time.Now().Add(t.ConnectTimeout)
if d, ok := ctx.Deadline(); !ok || deadline.Before(d) {
var cancel func()
ctx, cancel = context.WithDeadline(ctx, deadline)
defer cancel()
}
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, t.ConnectTimeout)
defer cancel()
}

if t.UseReuseport() {
Expand Down

0 comments on commit 649bdea

Please sign in to comment.