Open
Description
Go version
1.23.4
GoFrame version
2.8.3
Can this bug be reproduced with the latest release?
Yes
What did you do?
demo codes:
package db
import (
"github.com/gogf/gf/v2/os/gcache"
"context"
"fmt"
"time"
)
func GetTestCached(ctx context.Context) (res *string, err error) {
cacheKey := fmt.Sprintf("GetTest-%d", 1)
v, err := gcache.GetOrSetFuncLock(ctx, cacheKey, GetTest, 1*time.Minute)
if err != nil {
return nil, err
}
err = v.Struct(&res)
if err != nil {
return nil, err
}
return res, nil
}
func GetTest(ctx context.Context) (value interface{}, err error) {
var res *string
str := "123456789"
res = &str
return res,nil
}
func GetTest2Cached(ctx context.Context) (res *string, err error) {
cacheKey := fmt.Sprintf("GetTest2-%d", 1)
v, err := gcache.GetOrSetFuncLock(ctx, cacheKey, GetTest2, 1*time.Minute) //dead lock
//v, err := gcache.GetOrSetFunc(ctx, cacheKey, GetTest2, 1*time.Minute) //no dead lock
if err != nil {
return nil, err
}
err = v.Struct(&res)
if err != nil {
return nil, err
}
return res, nil
}
func GetTest2(ctx context.Context) (value interface{}, err error) {
var res *string
res,err = GetTestCached(ctx)
return res,nil
}
What did you see happen?
dead lock when calling GetTest2Cached
What did you expect to see?
I need to get some cached data as db query params, then save results in another cache key.
both need to use GetOrSetFuncLock besides GetOrSetFunc.