From 492af76bc8c493d2567080d357137ce7cab0f2c0 Mon Sep 17 00:00:00 2001 From: "fox.cpp" Date: Mon, 5 Jul 2021 18:46:18 +0300 Subject: [PATCH] client: Add read timeout for initial greeting --- client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client.go b/client.go index 4771985..4fbf819 100644 --- a/client.go +++ b/client.go @@ -91,6 +91,10 @@ func NewClient(conn net.Conn, host string) (*Client, error) { c.setConn(conn) + // Initial greeting timeout. RFC 5321 recommends 5 minutes. + c.conn.SetDeadline(time.Now().Add(5 * time.Minute)) + defer c.conn.SetDeadline(time.Time{}) + _, _, err := c.Text.ReadResponse(220) if err != nil { c.Text.Close()