New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto/tls: Conn.Close doesn't unblock stuck conn.Read #23518
Comments
my tls server go code like this: package main import ( var clientNum int32 = 0 func main() {
} func handleConnection(conn net.Conn) {
} func Log(v ...interface{}) { func CheckError(err error) { func monitor() {
} |
If the telnet client is actively closed, there is no problem |
Hi. I think the problem is some think like that:
seems it's a deadlock:
While we are making handshake |
Change https://golang.org/cl/90155 mentions this issue: |
The existing implementation of TLS connection has a deadlock. It occurs when client connects to TLS server and doesn't send data for handshake, so server calls Close on this connection. This is because server reads data under locked mutex, while Close method tries to lock the same mutex. Fixes golang#23518 Change-Id: I4fb0a2a770f3d911036bfd9a7da7cc41c1b27e19 Reviewed-on: https://go-review.googlesource.com/90155 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
The existing implementation of TLS connection has a deadlock. It occurs when client connects to TLS server and doesn't send data for handshake, so server calls Close on this connection. This is because server reads data under locked mutex, while Close method tries to lock the same mutex. Fixes golang#23518 Change-Id: I4fb0a2a770f3d911036bfd9a7da7cc41c1b27e19 Reviewed-on: https://go-review.googlesource.com/90155 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
Please answer these questions before submitting your issue. Thanks!
What did you do?
I write a tcp server using "crypto/tls", it listen on a port. just like this:
for {
conn, err := netListen.Accept()
if nil != err {
continue
}
go handleConnection(conn)
}
In handleConnection, a separate go routine recvFromTcp is created for TCP reading operation, and timeout judgement is made in the main goroutine. When 30 seconds can't get the TCP client's message, it will close the connection.
I use telnet to connect the server, and after 30 seconds the server-side determines the timeout, and the recvFromTcp group is stuck in Read when the Conn's Close () is called. Two go routine can't quit
What did you expect to see?
tcp server using "crypto/tls" , listen on a port ,when I run telnet on wondows, Server-side timeout judgment, one goroutine call Close() of net.Conn, conn.Read in another goroutine will return err immediately。
What did you see instead?
when one goroutine call Close() of net.Conn,conn.Read in another goroutine is blocked in Read。
System details
call Close in one goroutine:
another goroutine is blocked in Read of net.Conn:
The text was updated successfully, but these errors were encountered: