git » chasquid » commit 08a5d19

Add missing Close calls

author Alberto Bertogli
2016-10-08 11:16:27 UTC
committer Alberto Bertogli
2016-10-09 23:51:05 UTC
parent dbe3843e12145ca28424caa390c394b1bd594478

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 +5 -1
internal/courier/smtp.go +1 -0

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)