mirror of
https://github.com/golang/go
synced 2024-11-22 07:54:40 -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:
parent
8bc5ef6cd7
commit
3c3a86ccc7
@ -545,6 +545,19 @@ func TestTLSServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
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://") {
|
if !strings.HasPrefix(ts.URL, "https://") {
|
||||||
t.Fatalf("expected test TLS server to start with https://, got %q", ts.URL)
|
t.Fatalf("expected test TLS server to start with https://, got %q", ts.URL)
|
||||||
}
|
}
|
||||||
|
@ -178,13 +178,6 @@ func (srv *Server) newConn(rwc net.Conn) (c *conn, err os.Error) {
|
|||||||
br := bufio.NewReader(c.lr)
|
br := bufio.NewReader(c.lr)
|
||||||
bw := bufio.NewWriter(rwc)
|
bw := bufio.NewWriter(rwc)
|
||||||
c.buf = bufio.NewReadWriter(br, bw)
|
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
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,6 +555,12 @@ func (c *conn) serve() {
|
|||||||
log.Print(buf.String())
|
log.Print(buf.String())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if tlsConn, ok := c.rwc.(*tls.Conn); ok {
|
||||||
|
tlsConn.Handshake()
|
||||||
|
c.tlsState = new(tls.ConnectionState)
|
||||||
|
*c.tlsState = tlsConn.ConnectionState()
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
w, err := c.readRequest()
|
w, err := c.readRequest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user