Skip to content

When using Hook Select when querying data, if a coroutine is used internally and the Value() method or Sum() is called multiple times, there is a probability that a null value will be returned. (Confirm that the database has values) and no errors are reported #3238

@JB-fy

Description

@JB-fy

What version of Go and system type/arch are you using?
go1.20.4 linux/amd64

What version of GoFrame are you using?
2.5.6和2.6.1都同时存在该问题

Can this bug be re-produced with the latest release?
yes

What did you do?
以下代码和图片可以看到在使用Hook Select时,如果内部使用协程,进行多次Value()方法查询时,有概率数据返回为空(当Limit越多时出现概率越高),包括SUM()等内部调用了Value()方法的都有这种问题。但注意:调用One()或All()等方法完全不会有这种问题

	daoAuth.Action.Ctx(ctx).Hook(gdb.HookHandler{
		Select: func(ctx context.Context, in *gdb.HookSelectInput) (result gdb.Result, err error) {
			result, err = in.Next(ctx)
			if err != nil {
				return
			}
			var wg sync.WaitGroup
			for _, record := range result {
				wg.Add(1)
				go func(record gdb.Record) {
					defer wg.Done()
					fmt.Println(daoAuth.Action.Ctx(ctx).Where(`actionId`, record[`actionId`]).Value(`actionId`))
					fmt.Println(daoAuth.Action.Ctx(ctx).Where(`actionId`, record[`actionId`]).Value(`actionName`))
				}(record)
			}
			wg.Wait()
			return
		},
	}).Limit(5).All()

这里id3的数据返回空字符串
1704263788307
这里id4的数据返回0
1704264204020
使用One方法不会出现这种情况
1704264430297

Metadata

Metadata

Assignees

Labels

bugIt is confirmed a bug, but don't worry, we'll handle it.doneThis issue is done, which may be release in next version.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions