Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JB-fy opened this issue Jan 3, 2024 · 0 comments
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@JB-fy
Copy link

JB-fy commented Jan 3, 2024

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

@JB-fy JB-fy added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jan 3, 2024
@Issues-translate-bot Issues-translate-bot changed the title 数据查询时使用Hook Select时,如果内部使用协程,且多次调用Value()方法或Sum()等内部调用过Value()方法的时候,有概率出现返回空值(确认数据库有值)且无报错的情况 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 Jan 3, 2024
@gqcn gqcn self-assigned this Apr 11, 2024
@gqcn gqcn added the wip label Apr 11, 2024
gqcn added a commit that referenced this issue Apr 11, 2024
@gqcn gqcn added done This issue is done, which may be release in next version. and removed wip labels Apr 11, 2024
@gqcn gqcn closed this as completed Apr 11, 2024
gqcn added a commit that referenced this issue Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants