Skip to content

Commit

Permalink
Fix potential deadlock in ByParam
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 29, 2023
1 parent d47225c commit 250048e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions resources/page/pages_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,14 @@ func (p Pages) Reverse() Pages {
}

// ByParam sorts the pages according to the given page Params key.
//
// Adjacent invocations on the same receiver with the same paramsKey will return a cached result.
//
// This may safely be executed in parallel.
// Note that there's no caching set up for this method as there is a potential deadlock
// with the collator cache used for string sorting.
// But this sorts by individual page params, so it should not cache very well anyway.
func (p Pages) ByParam(paramsKey any) Pages {
if len(p) < 2 {
return p
}
paramsKeyStr := cast.ToString(paramsKey)
key := "pageSort.ByParam." + paramsKeyStr

stringLess, close := collatorStringLess(p[0])
defer close()
Expand Down Expand Up @@ -407,7 +405,9 @@ func (p Pages) ByParam(paramsKey any) Pages {

}

pages, _ := spc.get(key, pageBy(paramsKeyComparator).Sort, p)
pagesCopy := make(Pages, len(p))
copy(pagesCopy, p)
pageBy(paramsKeyComparator).Sort(pagesCopy)

return pages
return pagesCopy
}

0 comments on commit 250048e

Please sign in to comment.