Skip to content

Commit 2e07efc

Browse files
ahrtrk8s-infra-cherrypick-robot
authored andcommitted
Set a tlsHandshakeTimeout for tlsListener
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
1 parent 7a4b47b commit 2e07efc

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

client/pkg/transport/listener_tls.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import (
2323
"os"
2424
"strings"
2525
"sync"
26+
"time"
27+
)
28+
29+
const (
30+
// tlsHandshakeTimeout bounds how long a single TLS handshake may block.
31+
tlsHandshakeTimeout = 10 * time.Second
2632
)
2733

2834
// tlsListener overrides a TLS listener so it will reject client
@@ -143,6 +149,7 @@ func (l *tlsListener) acceptLoop() {
143149
}()
144150

145151
tlsConn := conn.(*tls.Conn)
152+
_ = tlsConn.SetDeadline(time.Now().Add(tlsHandshakeTimeout))
146153
herr := tlsConn.Handshake()
147154
pendingMu.Lock()
148155
delete(pending, conn)
@@ -152,6 +159,7 @@ func (l *tlsListener) acceptLoop() {
152159
l.handshakeFailure(tlsConn, herr)
153160
return
154161
}
162+
_ = tlsConn.SetDeadline(time.Time{})
155163
if err := l.check(ctx, tlsConn); err != nil {
156164
l.handshakeFailure(tlsConn, err)
157165
return

0 commit comments

Comments
 (0)