Skip to content

crypto/tls: c.ConnectionState deadlock when called from c.conn.Close #18426

Description

@sabey

What version of Go are you using (go version)?

go1.7

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

	c.handshakeMutex.Lock()
	defer c.handshakeMutex.Unlock()

	if c.handshakeComplete {
		alertErr = c.sendAlert(alertCloseNotify)
	}

	if err := c.conn.Close(); err != nil {
		// c.conn.Close() calls c.ConnectionState() before returning
		// this will cause a deadlock
		// can the defer be removed from c.handshakeMutex.Unlock() before c.conn.Close()?
		return err
	}

	return alertErr

}

What did you expect to see?

Close() will call c.handshakeMutex.Lock()
Close() will deadlock if c.conn.Close() calls ConnectionState()
https://golang.org/src/crypto/tls/conn.go?s=34139:34345#L1163
ConnectionState() will call c.handshakeMutex.Lock()
https://golang.org/src/crypto/tls/conn.go?s=36916:36964#L1271

What did you see instead?

Is there a reason I shouldn't be able to call ConnectionState from inside of my net.Conn that *tls.Conn is wrapped around?
Could the defer unlock be replaced?

thank you

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions