Browse Source

do not block in recvRoutine

pull/1095/head
Anton Kaliaev 7 years ago
parent
commit
22b038810a
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 6 additions and 5 deletions
  1. +4
    -4
      p2p/conn/connection.go
  2. +2
    -1
      p2p/conn/connection_test.go

+ 4
- 4
p2p/conn/connection.go View File

@ -153,7 +153,7 @@ func NewMConnectionWithConfig(conn net.Conn, chDescs []*ChannelDescriptor, onRec
sendMonitor: flow.New(0, 0),
recvMonitor: flow.New(0, 0),
send: make(chan struct{}, 1),
pong: make(chan struct{}),
pong: make(chan struct{}, 1),
onReceive: onReceive,
onError: onError,
config: config,
@ -191,7 +191,7 @@ func (c *MConnection) OnStart() error {
c.quit = make(chan struct{})
c.flushTimer = cmn.NewThrottleTimer("flush", c.config.FlushThrottle)
c.pingTimer = cmn.NewRepeatTimer("ping", c.config.PingInterval)
c.pongTimeoutCh = make(chan bool)
c.pongTimeoutCh = make(chan bool, 1)
c.chStatsTimer = cmn.NewRepeatTimer("chStats", updateStats)
go c.sendRoutine()
go c.recvRoutine()
@ -492,8 +492,8 @@ FOR_LOOP:
c.Logger.Debug("Receive Pong")
select {
case c.pongTimeoutCh <- false:
case <-c.quit:
break FOR_LOOP
default:
// never block
}
case packetTypeMsg:
pkt, n, err := msgPacket{}, int(0), error(nil)


+ 2
- 1
p2p/conn/connection_test.go View File

@ -22,10 +22,10 @@ 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 = 90 * time.Millisecond
cfg.PongTimeout = 45 * time.Millisecond
chDescs := []*ChannelDescriptor{&ChannelDescriptor{ID: 0x01, Priority: 1, SendQueueCapacity: 1}}
c := NewMConnectionWithConfig(conn, chDescs, onReceive, onError, cfg)
c.SetLogger(log.TestingLogger())
return c
@ -224,6 +224,7 @@ func TestMConnectionMultiplePings(t *testing.T) {
defer mconn.Stop()
// sending 3 pings in a row (abuse)
// see https://github.com/tendermint/tendermint/issues/1190
_, err = server.Write([]byte{packetTypePing})
require.Nil(t, err)
_, err = server.Read(make([]byte, 1))


Loading…
Cancel
Save