mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 03:24:40 -07:00
Fix TLS issue where server started to receive TLS data on non TLS connection.
Without the server fix, tls_test.go would likely report an error. The server would show a parser error with protocol snippet containing "random" bytes, likely encrypted data.
This commit is contained in:
@@ -92,7 +92,7 @@ func init() {
|
||||
}
|
||||
|
||||
// Lock should be held
|
||||
func (c *client) initClient() {
|
||||
func (c *client) initClient(tlsConn bool) {
|
||||
s := c.srv
|
||||
c.cid = atomic.AddUint64(&s.gcid, 1)
|
||||
c.bw = bufio.NewWriterSize(c.nc, s.opts.BufSize)
|
||||
@@ -130,11 +130,13 @@ func (c *client) initClient() {
|
||||
// ip.SetWriteBuffer(2 * s.opts.BufSize)
|
||||
// }
|
||||
|
||||
// Set the Ping timer
|
||||
c.setPingTimer()
|
||||
if !tlsConn {
|
||||
// Set the Ping timer
|
||||
c.setPingTimer()
|
||||
|
||||
// Spin up the read loop.
|
||||
go c.readLoop()
|
||||
// Spin up the read loop.
|
||||
go c.readLoop()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *client) readLoop() {
|
||||
|
||||
@@ -138,7 +138,7 @@ func (s *Server) createRoute(conn net.Conn, rURL *url.URL) *client {
|
||||
c.mu.Lock()
|
||||
|
||||
// Initialize
|
||||
c.initClient()
|
||||
c.initClient(tlsRequired)
|
||||
|
||||
c.Debugf("Route connection created")
|
||||
|
||||
@@ -182,6 +182,14 @@ func (s *Server) createRoute(conn net.Conn, rURL *url.URL) *client {
|
||||
// Rewrap bw
|
||||
c.bw = bufio.NewWriterSize(c.nc, s.opts.BufSize)
|
||||
|
||||
// Do final client initialization
|
||||
|
||||
// Set the Ping timer
|
||||
c.setPingTimer()
|
||||
|
||||
// Spin up the read loop.
|
||||
go c.readLoop()
|
||||
|
||||
c.Debugf("TLS handshake complete")
|
||||
cs := conn.ConnectionState()
|
||||
c.Debugf("TLS version %s, cipher suite %s", tlsVersion(cs.Version), tlsCipher(cs.CipherSuite))
|
||||
|
||||
@@ -439,7 +439,7 @@ func (s *Server) createClient(conn net.Conn) *client {
|
||||
c.mu.Lock()
|
||||
|
||||
// Initialize
|
||||
c.initClient()
|
||||
c.initClient(tlsRequired)
|
||||
|
||||
c.Debugf("Client connection created")
|
||||
|
||||
@@ -491,6 +491,14 @@ func (s *Server) createClient(conn net.Conn) *client {
|
||||
// Rewrap bw
|
||||
c.bw = bufio.NewWriterSize(c.nc, s.opts.BufSize)
|
||||
|
||||
// Do final client initialization
|
||||
|
||||
// Set the Ping timer
|
||||
c.setPingTimer()
|
||||
|
||||
// Spin up the read loop.
|
||||
go c.readLoop()
|
||||
|
||||
c.Debugf("TLS handshake complete")
|
||||
cs := conn.ConnectionState()
|
||||
c.Debugf("TLS version %s, cipher suite %s", tlsVersion(cs.Version), tlsCipher(cs.CipherSuite))
|
||||
|
||||
Reference in New Issue
Block a user