db.Preload("User").Find(&list)
这样执行是正常的。
go func(){
db.Preload("User").Find(&list)
}()
这样的话,偶尔会报错
User: unsupported relations
不知道是什么原因。有没有遇到过的告诉一下。是什么原因??
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
并发执行的时候,必现这个问题,不知道是使用的方式不对还是什么。
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
并发执行的时候,必现这个问题,不知道是使用的方式不对还是什么。
之前版本会panic,新版本改成了返回error,主要是relation是空的,不知道为什么没有把他们之间的关系解析出来
确定使用了新的Session,还是会返回error
db = db.Where("xxx")
tx := db.Session(&gorm.Session{})
go func(){
// 这里err依然不是nil
err:=tx.Preload("xxx").Find(XXX).Error
}()
确定使用了新的Session,还是会返回error
db = db.Where("xxx")
tx := db.Session(&gorm.Session{})
go func(){
// 这里err依然不是nil
err:=tx.Preload("xxx").Find(XXX).Error
}()
我也试过了,难道是使用方式不对么
建个 playground 的 pull request 我这边看看?
https://github.com/go-gorm/playground/pull/211
@jinzhu 看一下,应该是DATA RACE造成的,在没有缓存relations的情况下,直接并发使用preload
en,我已经知道原因了,因为第一次缓存了 schema, 但实际关联解析部分未处理完 https://github.com/go-gorm/gorm/blob/557b874ee3c9a6df9ffc5cd4a4bf2d89d3e788d5/schema/schema.go#L222
这时候另一个 routinue 请求过来,会取出未处理完的 schema, 触发的这个问题,应该只是在程序刚开始的时候会有问题,后续就不会了,我看看修复一下
@feige84 @zhaozong @jrkeen 最新 master 已修复,感谢!
作者辛苦了。给大家提供这么好的gorm。非常感谢。祝你工作顺利!
效率真高
@feige84 @zhaozong @jrkeen 最新 master 已修复,感谢!
单测我跑过了,去掉这一句还是有问题,单测能通过的原因就是这里已经在缓存过了,这一行去掉,单独跑这一个单测还是会报原来的错。
就是这里已经在缓存过了,这一行去掉,单独跑这一个单测还是会报原来的错。
你的那 个代码有问题,里面的 tx 改了全局变量,下面的加个 tx := 就好
就是这里已经在缓存过了,这一行去掉,单独跑这一个单测还是会报原来的错。
你的那 个代码有问题,里面的 tx 改了全局变量,下面的加个 tx := 就好
我跑的是master上你提交的单测,把上面我说的注释掉你多跑几次试试
就是这里已经在缓存过了,这一行去掉,单独跑这一个单测还是会报原来的错。
你的那 个代码有问题,里面的 tx 改了全局变量,下面的加个 tx := 就好
我跑的是master上你提交的单测,把上面我说的注释掉你多跑几次试试
确实这个测试不讲武德,我跑了几次都正常,还有个边缘情况有问题,刚刚也修复了
啪的一下就修复了,很快啊
Most helpful comment
en,我已经知道原因了,因为第一次缓存了 schema, 但实际关联解析部分未处理完 https://github.com/go-gorm/gorm/blob/557b874ee3c9a6df9ffc5cd4a4bf2d89d3e788d5/schema/schema.go#L222
这时候另一个 routinue 请求过来,会取出未处理完的 schema, 触发的这个问题,应该只是在程序刚开始的时候会有问题,后续就不会了,我看看修复一下