Comments (13)
你的代码是什么呢,发出来看看
from gf.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
What is your code? Send it and take a look.
from gf.
很正常的语句,使用的是内存缓存,数据库使用时sqlite,调试发现函数有正常执行到,但是返回后就会出现死锁,使用GetOrSetFunc正常使用
from gf.
// 创建表
create table issue3577(
id INT PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
age INT NOT NULL
)
// 插入一条数据
insert into issue3577 values(1,'wln',28);
type Issue3577 struct {
Id int `orm:"id"`
Name string `orm:"name"`
Age int `orm:"age"`
}
func init(){
gdb.AddConfigNode("sqlite", gdb.ConfigNode{
Link: "sqlite::@file(/testdb.sqlite3)",
})
}
func Test_issue3577(t *testing.T) {
ctx := context.TODO()
sqlite := g.DB("sqlite")
key := "isssue3577"
t.Log("连接sqlite成功,开始查询")
v, err := gcache.GetOrSetFuncLock(ctx, key, func(ctx context.Context) (value interface{}, err error) {
return test_issue3557_getone(ctx, sqlite)
}, 0)
t.Log("查询结束")
if err != nil {
t.Fatal(err)
}
t.Log("val=", v.Interface())
}
func test_issue3557_getone(_ context.Context, db gdb.DB) (val any, err error) {
res, err := db.Model("issue3577").One()
if err != nil {
return nil, err
}
data := Issue3577{}
err = res.Struct(&data)
return data, err
}
运行命令 go test -timeout 30s -run ^Test_issue3577$
运行上述代码,会死锁,可以自行查询打印的堆栈情况,
问题出现在当执行gcache.GetOrSetFuncLock ,
内部会调用(d *adapterMemoryData) SetWithLock,这个函数一开始就直接mu.Lock
然后在调用回调函数test_issue3557_getone的时候,
内部会调用(m *softTimeMaintainer) getSoftFieldNameAndType,文件路径: gf/database/gdb/gdb_model_soft_time.go:218
再往里面最终会调用(d *adapterMemoryData) Get,文件路径: gf/os/gcache/gcache_adapter_memory_data.go:145
这个函数一开始就调用了mu.RLock
,然后上面一开始调用的mu.Lock还没有解锁,所以就造成了死锁
from gf.
图片在上面发不出来,在这里发
from gf.
pr #3579 可以解决此bug
from gf.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
#3579 can solve this bug
from gf.
嗯嗯,我就是切换到默认的了
from gf.
只能先这样用了
from gf.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Yeah, okay, I just switched to the default one.
from gf.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
This is the only way to use it first
from gf.
Let me handle this.
from gf.
from gf.
Related Issues (20)
- database/gdb: scan zero value for google.protobuf.Timestamp HOT 3
- db/gdb query table, field to cache
- codecov: runing ci-mail.sh failed
- util/gvalid: json array validation is invalid HOT 2
- cmd/gf: gf run how to exclude dir or file ? HOT 2
- os/ghttp: stream流式输出可能存在bug HOT 6
- os/grpool: AddWithRecover Panic HOT 4
- os/gtime: issue config HOT 7
- gf gen dao use config database.default.link? HOT 4
- The fields in the structure will not be set to default values when requesting HOT 2
- If the request structure is a slice type structure, it is not bound to a value that meets the requirements. HOT 2
- gf gen ctrl bug
- database/gdb: I noticed there was a sharding feature before. Why was it removed HOT 1
- net/ghttp: openapi doc misses request parameter constraints when `CommonRequest` is set.
- Bug caused by combining ORM's List method and garry HOT 4
- database/gdb: Do you want to change the default Charset? HOT 3
- gf pack arg -p / not affect HOT 2
- database/gdb: create/update/delele time should not be overridden if it has been specified
- gf gen service -f CamelLower
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gf.