Add nil check in UpdateDeadline method

Ensure that the connection is not nil before setting the deadline in the UpdateDeadline method. This prevents a potential runtime panic when attempting to set a deadline on a nil connection.
This commit is contained in:
Winni Neessen 2024-11-11 18:07:31 +01:00
parent 5e3d14f842
commit 8fbd94a675
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -622,6 +622,9 @@ func (c *Client) HasConnection() bool {
func (c *Client) UpdateDeadline(timeout time.Duration) error { func (c *Client) UpdateDeadline(timeout time.Duration) error {
c.mutex.Lock() c.mutex.Lock()
defer c.mutex.Unlock() defer c.mutex.Unlock()
if c.conn == nil {
return errors.New("smtp: client has no connection")
}
if err := c.conn.SetDeadline(time.Now().Add(timeout)); err != nil { if err := c.conn.SetDeadline(time.Now().Add(timeout)); err != nil {
return fmt.Errorf("smtp: failed to update deadline: %w", err) return fmt.Errorf("smtp: failed to update deadline: %w", err)
} }