diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index 7c7cee344..25aac3012 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -34,8 +34,8 @@ const ( defaultSendRate = int64(512000) // 500KB/s defaultRecvRate = int64(512000) // 500KB/s defaultSendTimeout = 10 * time.Second - defaultPingInterval = 40 * time.Second - defaultPongTimeout = 35 * time.Second + defaultPingInterval = 60 * time.Second + defaultPongTimeout = 45 * time.Second ) type receiveCbFunc func(chID byte, msgBytes []byte) @@ -134,7 +134,7 @@ func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive recei // NewMConnectionWithConfig wraps net.Conn and creates multiplex connection with a config func NewMConnectionWithConfig(conn net.Conn, chDescs []*ChannelDescriptor, onReceive receiveCbFunc, onError errorCbFunc, config *MConnConfig) *MConnection { if config.pongTimeout >= config.pingInterval { - panic("pongTimeout must be less than pingInterval") + panic("pongTimeout must be less than pingInterval (otherwise, next ping will reset pong timer)") } mconn := &MConnection{ diff --git a/p2p/conn/connection_test.go b/p2p/conn/connection_test.go index 8ab865bf0..4fb8d3412 100644 --- a/p2p/conn/connection_test.go +++ b/p2p/conn/connection_test.go @@ -24,8 +24,8 @@ func createTestMConnection(conn net.Conn) *MConnection { func createMConnectionWithCallbacks(conn net.Conn, onReceive func(chID byte, msgBytes []byte), onError func(r interface{})) *MConnection { chDescs := []*ChannelDescriptor{&ChannelDescriptor{ID: 0x01, Priority: 1, SendQueueCapacity: 1}} cfg := DefaultMConnConfig() - cfg.pingInterval = 40 * time.Millisecond - cfg.pongTimeout = 35 * time.Millisecond + cfg.pingInterval = 60 * time.Millisecond + cfg.pongTimeout = 45 * time.Millisecond c := NewMConnectionWithConfig(conn, chDescs, onReceive, onError, cfg) c.SetLogger(log.TestingLogger()) return c @@ -119,7 +119,7 @@ func TestMConnectionStatus(t *testing.T) { assert.Zero(status.Channels[0].SendQueueSize) } -func TestPongTimeoutResultsInError(t *testing.T) { +func TestMConnectionPongTimeoutResultsInError(t *testing.T) { server, client := net.Pipe() defer server.Close() defer client.Close() @@ -142,7 +142,7 @@ func TestPongTimeoutResultsInError(t *testing.T) { server.Read(make([]byte, 1)) }() - expectErrorAfter := 10*time.Millisecond + mconn.config.pingInterval + mconn.config.pongTimeout + expectErrorAfter := (mconn.config.pingInterval + mconn.config.pongTimeout) * 2 select { case msgBytes := <-receivedCh: t.Fatalf("Expected error, but got %v", msgBytes)