1
0
mirror of https://github.com/golang/go synced 2024-11-12 05:40:22 -07:00

http: fix TLS handshake blocking server accept loop

Fixes #2263

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5076042
This commit is contained in:
Brad Fitzpatrick 2011-09-19 19:56:51 -07:00
parent 8bc5ef6cd7
commit 3c3a86ccc7
2 changed files with 19 additions and 7 deletions

View File

@ -545,6 +545,19 @@ func TestTLSServer(t *testing.T) {
}
}))
defer ts.Close()
// Connect an idle TCP connection to this server before we run
// our real tests. This idle connection used to block forever
// in the TLS handshake, preventing future connections from
// being accepted. It may prevent future accidental blocking
// in newConn.
idleConn, err := net.Dial("tcp", ts.Listener.Addr().String())
if err != nil {
t.Fatalf("Dial: %v", err)
}
defer idleConn.Close()
time.AfterFunc(10e9, func() { t.Fatalf("Timeout") })
if !strings.HasPrefix(ts.URL, "https://") {
t.Fatalf("expected test TLS server to start with https://, got %q", ts.URL)
}

View File

@ -178,13 +178,6 @@ func (srv *Server) newConn(rwc net.Conn) (c *conn, err os.Error) {
br := bufio.NewReader(c.lr)
bw := bufio.NewWriter(rwc)
c.buf = bufio.NewReadWriter(br, bw)
if tlsConn, ok := rwc.(*tls.Conn); ok {
tlsConn.Handshake()
c.tlsState = new(tls.ConnectionState)
*c.tlsState = tlsConn.ConnectionState()
}
return c, nil
}
@ -562,6 +555,12 @@ func (c *conn) serve() {
log.Print(buf.String())
}()
if tlsConn, ok := c.rwc.(*tls.Conn); ok {
tlsConn.Handshake()
c.tlsState = new(tls.ConnectionState)
*c.tlsState = tlsConn.ConnectionState()
}
for {
w, err := c.readRequest()
if err != nil {