Skip to content

Commit 60d48d9

Browse files
authored
Fix be rpc leaks in rpc factory (#299)
According to the golang document, the KeyType of a map may be any type that is comparable: 1. Two pointer values are equal if they point to the same variable or if both have value nil 2. Two struct values are equal if their corresponding non- blank field values are equal.
1 parent 1d1f35e commit 60d48d9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pkg/rpc/rpc_factory.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ type RpcFactory struct {
2020
feRpcs map[*base.Spec]IFeRpc
2121
feRpcsLock sync.Mutex
2222

23-
beRpcs map[*base.Backend]IBeRpc
23+
beRpcs map[base.Backend]IBeRpc
2424
beRpcsLock sync.Mutex
2525
}
2626

2727
func NewRpcFactory() IRpcFactory {
2828
return &RpcFactory{
2929
feRpcs: make(map[*base.Spec]IFeRpc),
30-
beRpcs: make(map[*base.Backend]IBeRpc),
30+
beRpcs: make(map[base.Backend]IBeRpc),
3131
}
3232
}
3333

@@ -57,7 +57,7 @@ func (rf *RpcFactory) NewFeRpc(spec *base.Spec) (IFeRpc, error) {
5757

5858
func (rf *RpcFactory) NewBeRpc(be *base.Backend) (IBeRpc, error) {
5959
rf.beRpcsLock.Lock()
60-
if beRpc, ok := rf.beRpcs[be]; ok {
60+
if beRpc, ok := rf.beRpcs[*be]; ok {
6161
rf.beRpcsLock.Unlock()
6262
return beRpc, nil
6363
}
@@ -77,6 +77,6 @@ func (rf *RpcFactory) NewBeRpc(be *base.Backend) (IBeRpc, error) {
7777

7878
rf.beRpcsLock.Lock()
7979
defer rf.beRpcsLock.Unlock()
80-
rf.beRpcs[be] = beRpc
80+
rf.beRpcs[*be] = beRpc
8181
return beRpc, nil
8282
}

0 commit comments

Comments
 (0)