mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
[FIXED] Server not sending PINGs to TSL connections (clients or routes)
- Removed unnecessary cast check to (*net.TCPConn). When the timer fires, the connection is already established. Replaced with check that connection has not been closed. - Add PING test that checks that pings are sent to TLS connections. - Changed Go version to 1.7.5 in travis. - Removed test package from code coverage.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.6.4
|
- 1.6.4
|
||||||
- 1.7.4
|
- 1.7.5
|
||||||
- 1.8
|
- 1.8
|
||||||
install:
|
install:
|
||||||
- go get github.com/nats-io/go-nats
|
- go get github.com/nats-io/go-nats
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ go test -v -covermode=atomic -coverprofile=./cov/auth.out ./auth
|
|||||||
go test -v -covermode=atomic -coverprofile=./cov/conf.out ./conf
|
go test -v -covermode=atomic -coverprofile=./cov/conf.out ./conf
|
||||||
go test -v -covermode=atomic -coverprofile=./cov/log.out ./logger
|
go test -v -covermode=atomic -coverprofile=./cov/log.out ./logger
|
||||||
go test -v -covermode=atomic -coverprofile=./cov/server.out ./server
|
go test -v -covermode=atomic -coverprofile=./cov/server.out ./server
|
||||||
go test -v -covermode=atomic -coverprofile=./cov/test.out ./test
|
go test -v -covermode=atomic -coverprofile=./cov/test.out -coverpkg=./server ./test
|
||||||
go test -v -covermode=atomic -coverprofile=./cov/test2.out -coverpkg=./server ./test
|
|
||||||
gocovmerge ./cov/*.out > acc.out
|
gocovmerge ./cov/*.out > acc.out
|
||||||
rm -rf ./cov
|
rm -rf ./cov
|
||||||
|
|
||||||
|
|||||||
@@ -1193,8 +1193,8 @@ func (c *client) processPingTimer() {
|
|||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
c.ptmr = nil
|
c.ptmr = nil
|
||||||
// Check if we are ready yet..
|
// Check if connection is still opened
|
||||||
if _, ok := c.nc.(*net.TCPConn); !ok {
|
if c.nc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -24,6 +26,68 @@ func runPingServer() *server.Server {
|
|||||||
return RunServer(&opts)
|
return RunServer(&opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPingSentToTLSConnection(t *testing.T) {
|
||||||
|
opts := DefaultTestOptions
|
||||||
|
opts.Port = PING_TEST_PORT
|
||||||
|
opts.PingInterval = PING_INTERVAL
|
||||||
|
opts.MaxPingsOut = PING_MAX
|
||||||
|
opts.TLSCert = "configs/certs/server-cert.pem"
|
||||||
|
opts.TLSKey = "configs/certs/server-key.pem"
|
||||||
|
opts.TLSCaCert = "configs/certs/ca.pem"
|
||||||
|
|
||||||
|
tc := server.TLSConfigOpts{}
|
||||||
|
tc.CertFile = opts.TLSCert
|
||||||
|
tc.KeyFile = opts.TLSKey
|
||||||
|
tc.CaFile = opts.TLSCaCert
|
||||||
|
|
||||||
|
opts.TLSConfig, _ = server.GenTLSConfig(&tc)
|
||||||
|
s := RunServer(&opts)
|
||||||
|
defer s.Shutdown()
|
||||||
|
|
||||||
|
c := createClientConn(t, "localhost", PING_TEST_PORT)
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
checkInfoMsg(t, c)
|
||||||
|
c = tls.Client(c, &tls.Config{InsecureSkipVerify: true})
|
||||||
|
tlsConn := c.(*tls.Conn)
|
||||||
|
tlsConn.Handshake()
|
||||||
|
|
||||||
|
cs := fmt.Sprintf("CONNECT {\"verbose\":%v,\"pedantic\":%v,\"ssl_required\":%v}\r\n", false, false, true)
|
||||||
|
sendProto(t, c, cs)
|
||||||
|
|
||||||
|
expect := expectCommand(t, c)
|
||||||
|
|
||||||
|
// Expect the max to be delivered correctly..
|
||||||
|
for i := 0; i < PING_MAX; i++ {
|
||||||
|
time.Sleep(PING_INTERVAL / 2)
|
||||||
|
expect(pingRe)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We should get an error from the server
|
||||||
|
time.Sleep(PING_INTERVAL)
|
||||||
|
expect(errRe)
|
||||||
|
|
||||||
|
// Server should close the connection at this point..
|
||||||
|
time.Sleep(PING_INTERVAL)
|
||||||
|
c.SetWriteDeadline(time.Now().Add(PING_INTERVAL))
|
||||||
|
|
||||||
|
var err error
|
||||||
|
for {
|
||||||
|
_, err = c.Write([]byte("PING\r\n"))
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.SetWriteDeadline(time.Time{})
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("No error: Expected to have connection closed")
|
||||||
|
}
|
||||||
|
if ne, ok := err.(net.Error); ok && ne.Timeout() {
|
||||||
|
t.Fatal("timeout: Expected to have connection closed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPingInterval(t *testing.T) {
|
func TestPingInterval(t *testing.T) {
|
||||||
s := runPingServer()
|
s := runPingServer()
|
||||||
defer s.Shutdown()
|
defer s.Shutdown()
|
||||||
|
|||||||
Reference in New Issue
Block a user