| 36 | } |
| 37 | |
| 38 | func (s *Server) acceptMuxConnections(listener net.Listener, httpListener *muxListener) error { |
| 39 | if s == nil || listener == nil { |
| 40 | return net.ErrClosed |
| 41 | } |
| 42 | |
| 43 | for { |
| 44 | conn, errAccept := listener.Accept() |
| 45 | if errAccept != nil { |
| 46 | return errAccept |
| 47 | } |
| 48 | if conn == nil { |
| 49 | continue |
| 50 | } |
| 51 | |
| 52 | // Dispatch each connection to a goroutine so that slow/idle clients |
| 53 | // cannot block the accept loop. Previously, TLS handshake and |
| 54 | // reader.Peek(1) were performed inline; an idle TCP connection that |
| 55 | // never sent bytes would block Peek indefinitely, preventing all |
| 56 | // subsequent connections from being accepted (issue #3267). |
| 57 | go s.routeMuxConnection(conn, httpListener) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // routeMuxConnection performs per-connection protocol detection and routing. |
| 62 | func (s *Server) routeMuxConnection(conn net.Conn, httpListener *muxListener) { |