Skip to content

Commit 2ed4f9a

Browse files
fix: close connection
1 parent 8de8a23 commit 2ed4f9a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

proxy/proxy.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"strconv"
1616
"strings"
1717
"sync/atomic"
18-
"time"
1918

2019
"github.com/coder/boundary/audit"
2120
"github.com/coder/boundary/rules"
@@ -119,19 +118,6 @@ func (p *Server) isStopped() bool {
119118
}
120119

121120
func (p *Server) handleConnectionWithTLSDetection(conn net.Conn) {
122-
//defer func() {
123-
// time.Sleep(time.Millisecond * 500)
124-
// _ = time.Sleep
125-
//
126-
// err := conn.Close()
127-
// if err != nil {
128-
// p.logger.Error("Failed to close connection", "error", err)
129-
// }
130-
//
131-
// p.logger.Debug("Successfully closed connection")
132-
//}()
133-
_ = time.Sleep
134-
135121
// Detect protocol using TLS handshake detection
136122
conn, isTLS := p.isTLSConnection(conn)
137123
if isTLS {
@@ -169,6 +155,13 @@ func (p *Server) isTLSConnection(conn net.Conn) (net.Conn, bool) {
169155
}
170156

171157
func (p *Server) handleHTTPConnection(conn net.Conn) {
158+
defer func() {
159+
err := conn.Close()
160+
if err != nil {
161+
p.logger.Error("Failed to close connection", "error", err)
162+
}
163+
}()
164+
172165
// Read HTTP request
173166
req, err := http.ReadRequest(bufio.NewReader(conn))
174167
if err != nil {
@@ -204,6 +197,13 @@ func (p *Server) handleTLSConnection(conn net.Conn) {
204197
// Create TLS connection
205198
tlsConn := tls.Server(conn, p.tlsConfig)
206199

200+
defer func() {
201+
err := tlsConn.Close()
202+
if err != nil {
203+
p.logger.Error("Failed to close TLS connection", "error", err)
204+
}
205+
}()
206+
207207
// Perform TLS handshake
208208
if err := tlsConn.Handshake(); err != nil {
209209
log.Printf("TLS handshake failed: %v", err)

0 commit comments

Comments
 (0)