Move mutex lock to sendSingleMsg method

Mutex locking was relocated from the Send method in client_120.go and client_119.go to sendSingleMsg in client.go. This ensures thread-safety specifically during the message transmission process.
This commit is contained in:
Winni Neessen 2024-09-27 14:03:50 +02:00
parent 6bd9a9c735
commit 253d065c83
Signed by: wneessen
GPG key ID: 385AC9889632126E
3 changed files with 3 additions and 6 deletions

View file

@ -801,6 +801,9 @@ func (c *Client) auth() error {
// sendSingleMsg sends out a single message and returns an error if the transmission/delivery fails. // sendSingleMsg sends out a single message and returns an error if the transmission/delivery fails.
// It is invoked by the public Send methods // It is invoked by the public Send methods
func (c *Client) sendSingleMsg(message *Msg) error { func (c *Client) sendSingleMsg(message *Msg) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if message.encoding == NoEncoding { if message.encoding == NoEncoding {
if ok, _ := c.smtpClient.Extension("8BITMIME"); !ok { if ok, _ := c.smtpClient.Extension("8BITMIME"); !ok {
return &SendError{Reason: ErrNoUnencoded, isTemp: false, affectedMsg: message} return &SendError{Reason: ErrNoUnencoded, isTemp: false, affectedMsg: message}

View file

@ -11,9 +11,6 @@ import "errors"
// Send sends out the mail message // Send sends out the mail message
func (c *Client) Send(messages ...*Msg) error { func (c *Client) Send(messages ...*Msg) error {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.checkConn(); err != nil { if err := c.checkConn(); err != nil {
return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)} return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)}
} }

View file

@ -13,9 +13,6 @@ import (
// Send sends out the mail message // Send sends out the mail message
func (c *Client) Send(messages ...*Msg) (returnErr error) { func (c *Client) Send(messages ...*Msg) (returnErr error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.checkConn(); err != nil { if err := c.checkConn(); err != nil {
returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)} returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)}
return return