Skip to content

Commit

Permalink
Fix deadlock in memrevcache (#1895)
Browse files Browse the repository at this point in the history
The current memrevcache code will deadlock on Insert, every time: Insert
takes the write lock at the top, and later calls Get, which tries to get
the read lock. This is an automatic deadlock.

Also:
- Fix some log identifiers in go PS handlers.
  • Loading branch information
kormat authored Sep 24, 2018
1 parent aefd33d commit e4f5a71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions go/lib/revcache/memrevcache/memrevcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func New(defaultExpiration, cleanupInterval time.Duration) revcache.RevCache {
func (c *memRevCache) Get(k *revcache.Key) (*path_mgmt.SignedRevInfo, bool) {
c.lock.RLock()
defer c.lock.RUnlock()
obj, ok := c.c.Get(k.String())
return c.get(k.String())
}

func (c *memRevCache) get(key string) (*path_mgmt.SignedRevInfo, bool) {
obj, ok := c.c.Get(key)
if !ok {
return nil, false
}
Expand All @@ -62,7 +66,7 @@ func (c *memRevCache) Insert(rev *path_mgmt.SignedRevInfo) bool {
}
k := revcache.NewKey(newInfo.IA(), newInfo.IfID)
key := k.String()
val, ok := c.Get(k)
val, ok := c.get(key)
if !ok {
c.c.Set(key, rev, ttl)
return true
Expand Down
8 changes: 4 additions & 4 deletions go/path_srv/internal/handlers/segreqcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *segReqCoreHandler) handleReq(ctx context.Context,
}
dstCore, err := h.isCoreDst(ctx, msger, segReq)
if err != nil {
h.logger.Error("[segReqHandler] Failed to determine dest type", "err", err)
h.logger.Error("[segReqCoreHandler] Failed to determine dest type", "err", err)
h.sendEmptySegReply(ctx, segReq, msger)
return
}
Expand All @@ -98,7 +98,7 @@ func (h *segReqCoreHandler) handleReq(ctx context.Context,
return
}
if len(downSegs) == 0 {
h.logger.Debug("[segReqHandler] no down segs found")
h.logger.Debug("[segReqCoreHandler] no down segs found")
h.sendEmptySegReply(ctx, segReq, msger)
return
}
Expand All @@ -118,7 +118,7 @@ func (h *segReqCoreHandler) handleReq(ctx context.Context,
retry := len(ias) == len(downIAs) && !segReq.Flags.CacheOnly
coreSegs, err = h.fetchCoreSegsFromDB(ctx, downIAs, retry)
if err != nil {
h.logger.Error("[segReqHandler] Failed to find core segs", "err", err)
h.logger.Error("[segReqCoreHandler] Failed to find core segs", "err", err)
h.sendEmptySegReply(ctx, segReq, msger)
return
}
Expand All @@ -133,7 +133,7 @@ func (h *segReqCoreHandler) handleReq(ctx context.Context,
return coreExists
})
}
h.logger.Debug("[segReqHandler] found segs", "core", len(coreSegs), "down", len(downSegs))
h.logger.Debug("[segReqCoreHandler] found segs", "core", len(coreSegs), "down", len(downSegs))
h.sendReply(ctx, msger, nil, coreSegs, downSegs, segReq)
}

Expand Down

0 comments on commit e4f5a71

Please sign in to comment.