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.
This commit is contained in:
Winni Neessen 2024-09-27 17:00:07 +02:00
parent 2d98c40cb6
commit 8791ce5a33
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -209,13 +209,13 @@ func (c *Client) StartTLS(config *tls.Config) error {
// not succeed. // not succeed.
func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) { func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool) {
c.mutex.RLock() c.mutex.RLock()
defer c.mutex.RUnlock()
tc, ok := c.conn.(*tls.Conn) tc, ok := c.conn.(*tls.Conn)
if !ok { if !ok {
return return
} }
state, ok = tc.ConnectionState(), true state, ok = tc.ConnectionState(), true
c.mutex.RUnlock()
return return
} }