GORM Playground Link
https://github.com/go-gorm/gorm/pull/5920
Description
当我调用 save 方法的时候,突然发现程序一直卡死,导致请求timeout
func (r *MuteRepo) Save(mute interface{}) (err error) {
return Db().Save(&mute).Error
}
虽然上面是一个错误的写法,但是对使用者来讲,如果这样调用会导致生产环境的崩溃,CPU飙升 原因在下面的代码块 finisher_api.go 第 76 行开始
reflectValue := reflect.Indirect(reflect.ValueOf(value))
for reflectValue.Kind() == reflect.Ptr || reflectValue.Kind() == reflect.Interface {
reflectValue = reflect.Indirect(reflectValue)
}
reflectValue 恒等于 reflect.Indirect(reflectValue),导致for循环一直存在 可以考虑加一层判断避免上游代码的错误导致整个服务的异常
reflectValue := reflect.Indirect(reflect.ValueOf(value))
for reflectValue.Kind() == reflect.Ptr || reflectValue.Kind() == reflect.Interface {
reflectIndirect := reflect.Indirect(reflectValue)
if reflectValue == reflectIndirect {
tx.AddError(ErrReflect)
return
}
reflectValue = reflectIndirect
}
Comment From: github-actions[bot]
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 30 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 ✨
Comment From: github-actions[bot]
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 30 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 ✨