Skip to content

Commit c6ef8d5

Browse files
committed
Add debugging for TLS connection hangs in CONNECT handling
- Add read timeout to detect clients that don't send HTTP requests - Add detailed TLS connection state logging - Better error handling for timeout scenarios This should help diagnose why CONNECT tunnels hang after TLS handshake.
1 parent 3329580 commit c6ef8d5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

proxy/proxy.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ func (p *Server) handleConnect(w http.ResponseWriter, r *http.Request) {
307307
}
308308
p.logger.Debug("TLS handshake successful", "hostname", hostname)
309309

310+
// Log connection state after handshake
311+
state := tlsConn.ConnectionState()
312+
p.logger.Debug("TLS connection established", "hostname", hostname, "version", state.Version, "cipher_suite", state.CipherSuite, "negotiated_protocol", state.NegotiatedProtocol)
313+
310314
// Now we have a TLS connection - handle HTTPS requests
311315
p.logger.Debug("Starting HTTPS request handling", "hostname", hostname)
312316
p.handleTLSConnection(tlsConn, hostname)
@@ -317,6 +321,9 @@ func (p *Server) handleConnect(w http.ResponseWriter, r *http.Request) {
317321
func (p *Server) handleTLSConnection(tlsConn *tls.Conn, hostname string) {
318322
p.logger.Debug("Creating HTTP server for TLS connection", "hostname", hostname)
319323

324+
// Set read timeout to detect hanging connections
325+
tlsConn.SetReadTimeout(5 * time.Second)
326+
320327
// Use ReadRequest to manually read HTTP requests from the TLS connection
321328
bufReader := bufio.NewReader(tlsConn)
322329
for {
@@ -325,6 +332,8 @@ func (p *Server) handleTLSConnection(tlsConn *tls.Conn, hostname string) {
325332
if err != nil {
326333
if err == io.EOF {
327334
p.logger.Debug("TLS connection closed by client", "hostname", hostname)
335+
} else if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
336+
p.logger.Debug("TLS connection read timeout - client not sending HTTP requests", "hostname", hostname)
328337
} else {
329338
p.logger.Debug("Failed to read HTTP request", "hostname", hostname, "error", err)
330339
}
@@ -511,4 +520,4 @@ func (sl *singleConnectionListener) Addr() net.Addr {
511520
return nil
512521
}
513522
return sl.conn.LocalAddr()
514-
}
523+
}

0 commit comments

Comments
 (0)