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

server: session variables was not changed when execute the mysql command 'ComChangeUser' #33699

Closed
knull-cn opened this issue Apr 2, 2022 · 5 comments · Fixed by #33703
Closed
Assignees
Labels
affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@knull-cn
Copy link
Contributor

knull-cn commented Apr 2, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  • set some session variable
  • execute 'ComChangeUser'
  • show the session variable , the values was the previous session setted(not the default values)

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

show session variable should the default values.

3. What did you see instead (Required)

the values was the previous session setted

4. What is your TiDB version? (Required)

v5.3.0

@knull-cn knull-cn added the type/bug The issue is confirmed as a bug. label Apr 2, 2022
@knull-cn
Copy link
Contributor Author

knull-cn commented Apr 2, 2022

problem : https://asktug.com/t/topic/662908
for java example code

import java.sql.*;

import com.mysql.cj.jdbc.JdbcConnection;

public class Client {
    public static void main(String args[]) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            JdbcConnection con = (JdbcConnection) DriverManager.getConnection("jdbc:mysql://localhost:4000/test", "root", "tidb");

            ResultSet rs = con.createStatement().executeQuery("select @a;");
            if (rs.next()) {
                String i = rs.getString(1);
                System.out.println("before set : a= " + i);
            }
            con.createStatement().execute("set @a = 1;");
            rs.close();
            rs = con.createStatement().executeQuery("select @a;");
            if (rs.next()) {
                String i = rs.getString(1);
                System.out.println("after set : a= " + i);
            }
           // switch anther user.
            con.changeUser("tidb", "tidb");

            rs = con.createStatement().executeQuery("select @a;");
            if (rs.next()) {
                String i = rs.getString(1);
                System.out.println("after changeUser : a= " + i);
            }

            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

@knull-cn
Copy link
Contributor Author

knull-cn commented Apr 2, 2022

After #24991, TiDB create new ctx object in clientConn::openSessionAndDoAuth https://github.com/pingcap/tidb/blob/v5.2.0/server/conn.go#L768-L776 .

but in handleChangeUser, ctx only call close but not set nil , so can't create new ctx, and use old session variables , see here : https://github.com/pingcap/tidb/blob/v5.2.0/server/conn.go#L2170-L2178

this was import with v5.2.0 and affected all version after v5.2.0

@bb7133
Copy link
Member

bb7133 commented Apr 3, 2022

@knull-cn Thanks! Since you've found the root cause, are you interested in closing it by a PR?

@knull-cn
Copy link
Contributor Author

knull-cn commented Apr 3, 2022

@knull-cn Thanks! Since you've found the root cause, are you interested in closing it by a PR?

yes , It is my pleasure.

@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 labels Apr 3, 2022
@ChenPeng2013 ChenPeng2013 added the sig/sql-infra SIG: SQL Infra label Apr 6, 2022
@Defined2014 Defined2014 added affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 labels Apr 6, 2022
@tiancaiamao
Copy link
Contributor

!!- Note for cherry-picker -!!: the fix PR for this one would introduce other bug #33892
So they must be handled together!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants