Skip to content

Commit bcdd15b

Browse files
committed
ensureConnectionCache should only create a cache if one does not exist. #699
1 parent 8adf4d8 commit bcdd15b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

plugin/plugin.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,21 @@ func (p *Plugin) shutdown() {
236236
}
237237

238238
func (p *Plugin) ensureConnectionCache(connectionName string) (*connectionmanager.ConnectionCache, error) {
239+
p.connectionCacheMapLock.Lock()
240+
defer p.connectionCacheMapLock.Unlock()
241+
242+
// check if we already have a cache
243+
if cache, ok := p.connectionCacheMap[connectionName]; ok {
244+
return cache, nil
245+
}
246+
247+
// add to map of connection caches
239248
maxCost := int64(100000 / len(p.ConnectionMap))
240249
connectionCache, err := connectionmanager.NewConnectionCache(connectionName, maxCost)
241250
if err != nil {
242251
return nil, err
243252
}
244253

245-
p.connectionCacheMapLock.Lock()
246-
defer p.connectionCacheMapLock.Unlock()
247-
// add to map of connection caches
248254
p.connectionCacheMap[connectionName] = connectionCache
249255
return connectionCache, nil
250256
}

0 commit comments

Comments
 (0)