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

planner: GetParamSQLFromAST is not thread-safe #43255

Closed
qw4990 opened this issue Apr 20, 2023 · 1 comment
Closed

planner: GetParamSQLFromAST is not thread-safe #43255

qw4990 opened this issue Apr 20, 2023 · 1 comment
Labels

Comments

@qw4990
Copy link
Contributor

qw4990 commented Apr 20, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Use the test below to reproduce:

	n := 100
	sqls := make([]string, 0, n)
	for i := 0; i < n; i++ {
		sqls = append(sqls, fmt.Sprintf(`insert into t values (%d, %d, %d)`, i*3+0, i*3+1, i*3+2))
	}
	stmts := make([]ast.StmtNode, 0, n)
	for _, sql := range sqls {
		stmt, err := parser.New().ParseOneStmt(sql, "", "")
		require.Nil(t, err)
		stmts = append(stmts, stmt)
	}

	var wg sync.WaitGroup
	for i := 0; i < n; i++ {
		wg.Add(1)
		go func(id int) {
			for i := 0; i < 1000; i++ {
				_, vals, err := GetParamSQLFromAST(context.Background(), MockContext(), stmts[id])
				require.Nil(t, err)
				require.Equal(t, len(vals), 3)
				require.Equal(t, vals[0].GetValue(), int64(id*3+0))
				require.Equal(t, vals[1].GetValue(), int64(id*3+1))
				require.Equal(t, vals[2].GetValue(), int64(id*3+2))
				time.Sleep(time.Millisecond + time.Duration(rand.Intn(int(time.Millisecond))))
			}
			wg.Done()
		}(i)
	}
	wg.Wait()

2. What did you expect to see? (Required)

No error

3. What did you see instead (Required)

Can't pass the test, some require.Equal might return errors.

4. What is your TiDB version? (Required)

@qw4990
Copy link
Contributor Author

qw4990 commented Apr 20, 2023

Fixed by #43242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant