From 250048e16480e43727d0d019a64b0adf0b0b53a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 29 May 2023 11:15:07 +0200 Subject: [PATCH] Fix potential deadlock in ByParam Fixes #11039 --- resources/page/pages_sort.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/page/pages_sort.go b/resources/page/pages_sort.go index b9b905cc227..7c94811d881 100644 --- a/resources/page/pages_sort.go +++ b/resources/page/pages_sort.go @@ -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() @@ -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 }