From 8791ce5a3354005905f05398c027149261a5220d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 27 Sep 2024 17:00:07 +0200 Subject: [PATCH] Fix deferred mutex unlock in TLSConnectionState Correct the sequence of mutex unlocking in TLSConnectionState to ensure the mutex is always released properly. This prevents potential deadlocks and ensures the function behaves as expected in a concurrent context. --- smtp/smtp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smtp/smtp.go b/smtp/smtp.go index 379f5fe..4ea1a3d 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -209,13 +209,13 @@ func (c *Client) StartTLS(config *tls.Config) error { // not succeed. func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) { c.mutex.RLock() + defer c.mutex.RUnlock() tc, ok := c.conn.(*tls.Conn) if !ok { return } state, ok = tc.ConnectionState(), true - c.mutex.RUnlock() return }