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

SET SESSION_STATES will not change the resource group connection count #54545

Closed
YangKeao opened this issue Jul 10, 2024 · 0 comments · Fixed by #54546
Closed

SET SESSION_STATES will not change the resource group connection count #54545

YangKeao opened this issue Jul 10, 2024 · 0 comments · Fixed by #54546
Assignees
Labels

Comments

@YangKeao
Copy link
Member

Bug Report

1. Minimal reproduce step (Required)

The following test will fail:

	// The resource group set by `SET SESSION_STATE` will be tracked by the counter
	// At first, create a new cert/key pair to encode session state
	tempDir := t.TempDir()
	certPath := filepath.Join(tempDir, "cert.pem")
	keyPath := filepath.Join(tempDir, "key.pem")
	err := util.CreateCertificates(certPath, keyPath, 1024, x509.RSA, x509.UnknownSignatureAlgorithm)
	require.NoError(t, err)

	sessionstates.SetCertPath(certPath)
	sessionstates.SetKeyPath(keyPath)
	sessionstates.ReloadSigningCert()
	cli.RunTests(t, nil, func(dbt *testkit.DBTestKit) {
		ctx := context.Background()
		conn, err := dbt.GetDB().Conn(ctx)
		require.NoError(t, err)
		resourceGroupConnCountReached(t, "default", 1.0)
		// Now set the resource group to `test`
		_, err = conn.ExecContext(ctx, "set resource group test")
		require.NoError(t, err)
		resourceGroupConnCountReached(t, "default", 0.0)
		resourceGroupConnCountReached(t, "test", 1.0)

		// Encode the session state
		rows, err := conn.QueryContext(ctx, "show session_states")
		require.NoError(t, err)
		var sessionStates, signInfo string
		rows.Next()
		err = rows.Scan(&sessionStates, &signInfo)
		require.NoError(t, err)
		require.NoError(t, rows.Close())

		// Now reset the resource group to `default`
		_, err = conn.ExecContext(ctx, "set resource group default")
		require.NoError(t, err)
		resourceGroupConnCountReached(t, "default", 1.0)
		resourceGroupConnCountReached(t, "test", 0.0)
		// Set the session state
		sessionStates = strings.ReplaceAll(sessionStates, "\\", "\\\\")
		sessionStates = strings.ReplaceAll(sessionStates, "'", "\\'")
		_, err = conn.ExecContext(ctx, fmt.Sprintf("set session_states '%s'", sessionStates))
		require.NoError(t, err)
		resourceGroupConnCountReached(t, "default", 0.0)
		resourceGroupConnCountReached(t, "test", 1.0)
	})

Instead, the count of default resource group is always 1.

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

Successfully merging a pull request may close this issue.

1 participant