From 08a5d19941f0329d02b1a350cd3652ed3ddd6c30 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 8 Oct 2016 12:16:27 +0100 Subject: [PATCH] Add missing Close calls The SMTP courier was not properly closing the connection, and chasquid's closing of incoming connections was not ideal (it was closing the underlying one, not necessarily the active one, like in the case of a jump to TLS). This patch fixes both by adding the missing calls to Close. --- chasquid.go | 6 +++++- internal/courier/smtp.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/chasquid.go b/chasquid.go index 1ed8087..ae5b261 100644 --- a/chasquid.go +++ b/chasquid.go @@ -445,8 +445,12 @@ type Conn struct { commandTimeout time.Duration } +func (c *Conn) Close() { + c.netconn.Close() +} + func (c *Conn) Handle() { - defer c.netconn.Close() + defer c.Close() c.tr = trace.New("SMTP.Conn", c.netconn.RemoteAddr().String()) defer c.tr.Finish() diff --git a/internal/courier/smtp.go b/internal/courier/smtp.go index 71fcb11..6e3b916 100644 --- a/internal/courier/smtp.go +++ b/internal/courier/smtp.go @@ -57,6 +57,7 @@ retry: if err != nil { return tr.Errorf("Could not dial: %v", err), false } + defer conn.Close() conn.SetDeadline(time.Now().Add(smtpTotalTimeout)) c, err := smtp.NewClient(conn, mx)