Unverified Commit 464e0165 authored by Jeromy's avatar Jeromy Committed by Jakub Sztandera

Respect context deadlines

parent 715d488a
......@@ -90,6 +90,11 @@ func dial(ctx context.Context, dialer net.Dialer, netw, addr string) (c net.Conn
deadline = time.Now().Add(dialer.Timeout)
}
ctxdeadline, ok := ctx.Deadline()
if ok && ctxdeadline.Before(deadline) {
deadline = ctxdeadline
}
localSockaddr = sockaddrnet.NetAddrToSockaddr(dialer.LocalAddr)
remoteSockaddr = sockaddrnet.NetAddrToSockaddr(netAddr)
......@@ -138,6 +143,11 @@ func dial(ctx context.Context, dialer net.Dialer, netw, addr string) (c net.Conn
if err = connect(ctx, fd, remoteSockaddr, deadline); err != nil {
syscall.Close(fd)
select {
case <-ctx.Done():
return nil, err
default:
}
continue // try again.
}
......
......@@ -454,6 +454,10 @@ func TestPacketListenDialSamePort(t *testing.T) {
t.Fatal(err)
}
if err := c1.SetReadDeadline(time.Now().Add(time.Second * 2)); err != nil {
t.Fatal(err)
}
if _, err := c1.Read(hello2); err != nil {
t.Fatal(err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment