Skip to content

Commit

Permalink
Handle tls.Conn handshake timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus authored and emersion committed Oct 6, 2021
1 parent 69690c3 commit 62f6b38
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ func (s *Server) handleConn(c *Conn) error {
s.locker.Unlock()
}()

if tlsConn, ok := c.conn.(*tls.Conn); ok {
if d := s.ReadTimeout; d != 0 {
c.conn.SetReadDeadline(time.Now().Add(d))
}
if d := s.WriteTimeout; d != 0 {
c.conn.SetWriteDeadline(time.Now().Add(d))
}
if err := tlsConn.Handshake(); err != nil {
s.ErrorLog.Printf("TLS handshake error for %s: %v", tlsConn.RemoteAddr(), err)
return err
}
}

c.greet()

for {
Expand Down

0 comments on commit 62f6b38

Please sign in to comment.