From 23c71d608f5540da3120176e004448cf833241e6 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 27 Sep 2024 10:33:28 +0200 Subject: [PATCH] Lock mutex before checking connection in Send method Added mutex locking in the `Send` method for both `client_120.go` and `client_119.go`. This ensures thread-safe access to the connection checks and prevents potential race conditions. --- client_119.go | 3 +++ client_120.go | 1 + 2 files changed, 4 insertions(+) diff --git a/client_119.go b/client_119.go index 7de5d59..0b05061 100644 --- a/client_119.go +++ b/client_119.go @@ -11,6 +11,9 @@ import "errors" // Send sends out the mail message func (c *Client) Send(messages ...*Msg) error { + c.mutex.Lock() + defer c.mutex.Unlock() + if err := c.checkConn(); err != nil { return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)} } diff --git a/client_120.go b/client_120.go index 729069b..5bb291d 100644 --- a/client_120.go +++ b/client_120.go @@ -15,6 +15,7 @@ import ( func (c *Client) Send(messages ...*Msg) (returnErr error) { c.mutex.Lock() defer c.mutex.Unlock() + if err := c.checkConn(); err != nil { returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)} return