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

SNOW-937188 pool mode where changed session gets destroyed [WIP] #934

Conversation

sfc-gh-mhofman
Copy link
Collaborator

@sfc-gh-mhofman sfc-gh-mhofman commented Apr 26, 2024

Description

When ChangedSession=Destroy is set in a connection string and a session is affected with a USE DATABASE/SCHEMA/ROLE/WAREHOUSE it is treated as no-longer matching original pool and gets destroyed on closing.
Its a non default pool behavior.

Checklist

  • Code compiles correctly
  • Code is formatted according to Coding Conventions
  • Created tests which fail without the change (if possible)
  • All tests passing (dotnet test)
  • Extended the README / documentation, if necessary
  • Provide JIRA issue id (if possible) or GitHub issue id in PR name

@sfc-gh-mhofman sfc-gh-mhofman requested a review from a team as a code owner April 26, 2024 20:31
Copy link

gitguardian bot commented Apr 26, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@sfc-gh-mhofman sfc-gh-mhofman changed the base branch from master to pool/SNOW-860872-connection-pool April 26, 2024 20:32
…some of its settings gets changed and no longer match the pool initial setup
@sfc-gh-mhofman sfc-gh-mhofman force-pushed the pool/SNOW-937188-changed-session branch from c44f234 to e727d1a Compare April 29, 2024 10:54
if (session.SessionPropertiesChanged && _poolConfig.ChangedSession == ChangedSessionBehavior.Destroy)
{
session.SetPooling(false);
Task.Run(() => session.CloseAsync(CancellationToken.None)).ConfigureAwait(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why just not to forget about the session letting dispose by Garbage Collector do the job?
what is the difference between this case and a case when someone manually set poolingEnabled = false on the session? In case of session.poolingEnabled = false we just decrease busy session counter and return false. I think both cases are very similar so they should be handled in a similar way.

internal string schema;
internal string role;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should user be also here?

Copy link
Collaborator Author

@sfc-gh-mhofman sfc-gh-mhofman Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no such thing in login response's SessionData object:

{
this.schema = schemaName;
if (!String.IsNullOrEmpty(initialSessionValue) && initialSessionValue != finalSessionValue)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use for non-quoted values use ignoring case comparison?

{
[TestFixture]
[NonParallelizable]
public class ConnectionChangedSessionIT : SFBaseTest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe ConnectionMultiplePoolsChangedSessionIT? it would be more visible that it is a test for the new pool

[NonParallelizable]
public class ConnectionChangedSessionIT : SFBaseTest
{
private readonly QueryExecResponseData _queryExecResponseChangedRole = new()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW do we want it to work for old pool as well? As I see the implementation - it would work for old pool as well. Don't we want to cover that in tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets have it only in latest pool (the least changes to prev the better)

[NonParallelizable]
public class ConnectionChangedSessionIT : SFBaseTest
{
private readonly QueryExecResponseData _queryExecResponseChangedRole = new()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the parameters that can cause not returning session to the pool should be covered in tests (so making one of them excluded from list should make some test to fail). But currently I think the situation is different. For example if the role has changed - it is only checked in the test for default pool mode which is OriginalPool, and is not covered in Destroy test. So I would add more unit tests to SFSessionTests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree but on the other side any changed is handled equally
https://github.com/snowflakedb/snowflake-connector-net/pull/934/files#diff-c36410e4608c5d3a815bdfa7327569a75af2ead26f4e5e67ab0f5f421120f6bdR476
I'm not sure we want to run each test 16 times in this case?

@sfc-gh-mhofman sfc-gh-mhofman changed the title SNOW-937188 pool mode where changed session gets destroyed SNOW-937188 pool mode where changed session gets destroyed [WIP] Apr 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2024
@sfc-gh-mhofman sfc-gh-mhofman deleted the pool/SNOW-937188-changed-session branch May 8, 2024 12:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants