From 1abe280957c230cd9aa78f174e5de1f43d63327b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Wed, 20 May 2020 08:38:18 +0200 Subject: [PATCH] Set timeout and deadline in DownloadDCC --- pkg/irc/client.go | 1 + pkg/irc/conn.go | 3 --- pkg/irc/dcc.go | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/irc/client.go b/pkg/irc/client.go index fc30a0df..c5965d7e 100644 --- a/pkg/irc/client.go +++ b/pkg/irc/client.go @@ -58,6 +58,7 @@ func NewClient(nick, username string) *Client { out: make(chan string, 32), quit: make(chan struct{}), reconnect: make(chan struct{}), + dialer: &net.Dialer{Timeout: 10 * time.Second}, recvBuf: make([]byte, 0, 4096), backoff: &backoff.Backoff{ Min: 500 * time.Millisecond, diff --git a/pkg/irc/conn.go b/pkg/irc/conn.go index f4ada4a8..7a3249ce 100644 --- a/pkg/irc/conn.go +++ b/pkg/irc/conn.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "errors" "fmt" - "net" "strings" "time" ) @@ -29,7 +28,6 @@ func (c *Client) Connect(address string) { c.Host = address[:idx] } c.Server = address - c.dialer = &net.Dialer{Timeout: 10 * time.Second} c.connChange(false, nil) go c.run() @@ -244,7 +242,6 @@ func (c *Client) recv() { if c.HandleNickInUse != nil { go c.writeNick(c.HandleNickInUse(msg.Params[1])) } - } c.Messages <- msg diff --git a/pkg/irc/dcc.go b/pkg/irc/dcc.go index 1595b33e..daef9e34 100644 --- a/pkg/irc/dcc.go +++ b/pkg/irc/dcc.go @@ -56,7 +56,7 @@ func DownloadDCC(w io.Writer, pack *DCCSend, progress chan DownloadProgress) err } } - conn, err := net.Dial("tcp", net.JoinHostPort(pack.IP, pack.Port)) + conn, err := net.DialTimeout("tcp", net.JoinHostPort(pack.IP, pack.Port), 10*time.Second) if err != nil { return err } @@ -70,6 +70,7 @@ func DownloadDCC(w io.Writer, pack *DCCSend, progress chan DownloadProgress) err prevUpdate := start for { + conn.SetReadDeadline(time.Now().Add(10 * time.Second)) n, err := conn.Read(buf) if err != nil { if err != io.EOF {