peer: gc active sub conn
This commit is contained in:
parent
b0c0e4b26e
commit
e97e6b68c6
@ -222,8 +222,15 @@ func (p *peer) gc(ttl time.Duration) {
|
||||
select {
|
||||
case <-act.Closed():
|
||||
delete(p.active, act)
|
||||
continue
|
||||
default:
|
||||
}
|
||||
if act.LastUsage().Before(minLastUsage) {
|
||||
log.Warn("close active connection because no activity", zap.String("peerId", p.id), zap.String("addr", p.Addr()))
|
||||
_ = act.Close()
|
||||
delete(p.active, act)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -105,6 +105,7 @@ func TestPeer_TryClose(t *testing.T) {
|
||||
}()
|
||||
defer out2.Close()
|
||||
fx.mc.EXPECT().Open(gomock.Any()).Return(in2, nil)
|
||||
fx.mc.EXPECT().Addr().Return("")
|
||||
dc2, err := fx.AcquireDrpcConn(ctx)
|
||||
require.NoError(t, err)
|
||||
_ = dc2.Close()
|
||||
@ -118,6 +119,18 @@ func TestPeer_TryClose(t *testing.T) {
|
||||
fx.mc.EXPECT().Open(gomock.Any()).Return(in3, nil)
|
||||
dc3, err := fx.AcquireDrpcConn(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// make another active, should be removed by ttl
|
||||
in4, out4 := net.Pipe()
|
||||
go func() {
|
||||
handshake.IncomingProtoHandshake(ctx, out4, defaultProtoChecker)
|
||||
}()
|
||||
defer out4.Close()
|
||||
fx.mc.EXPECT().Open(gomock.Any()).Return(in4, nil)
|
||||
dc4, err := fx.AcquireDrpcConn(ctx)
|
||||
require.NoError(t, err)
|
||||
defer dc4.Close()
|
||||
|
||||
fx.ReleaseDrpcConn(dc3)
|
||||
_ = dc3.Close()
|
||||
fx.ReleaseDrpcConn(dc)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user