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-1198472: Connection Pool . For the same connection the session id keeps to be the same #789

Closed
Lumengrid opened this issue Mar 4, 2024 · 4 comments
Assignees
Labels
status-triage_done Initial triage done, will be further handled by the driver team

Comments

@Lumengrid
Copy link

Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!

  1. What version of NodeJS driver are you using?
    1.8.0

  2. What operating system and processor architecture are you using?
    Mac M1 Pro

  3. What version of NodeJS are you using?
    (node --version and npm --version)
    v12.22.12

  4. What are the component versions in the environment (npm list)?
    ...

5.Server version:* E.g. 1.90.1
You may get the server version by running a query:
8.8.4

  1. What did you do?
    Creating a connection pool, when I acquire and release a connection.
    For the same connection id this keeps the same session id.

  2. What did you expect to see?
    After Acquiring the session id it must be different from before

  3. Can you set logging to DEBUG and collect the logs?
    yes

@Lumengrid Lumengrid added the bug Something isn't working label Mar 4, 2024
@github-actions github-actions bot changed the title Connection Pool . For the same connection the session id keeps to be the same SNOW-1198472: Connection Pool . For the same connection the session id keeps to be the same Mar 4, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Mar 4, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage Issue is under initial triage and removed bug Something isn't working labels Mar 4, 2024
@sfc-gh-dszmolka
Copy link
Collaborator

sfc-gh-dszmolka commented Mar 4, 2024

hi and thank you for raising this issue. Snowflake Sessions themselves are by default kept open indefinitely, or until the authentication token expires.

when they are no longer needed, the connection associated with them must be closed.

can you please provide a code snippet / small repro program on how you close the connection which is then again re-acquireable from the pool somehow, and is still associated with the same Snowflake Session?

Thank you in advance !

@sfc-gh-dszmolka sfc-gh-dszmolka added the status-information_needed Additional information is required from the reporter label Mar 4, 2024
@Lumengrid
Copy link
Author

hi and thank you for raising this issue. Snowflake Sessions themselves are by default kept open indefinitely, or until the authentication token expires.

when they are no longer needed, the connection associated with them must be closed.

can you please provide a code snippet / small repro program on how you close the connection which is then again re-acquireable from the pool somehow, and is still associated with the same Snowflake Session?

Thank you in advance !

Hi, we get the connection by doing this

const connection = await global.snowflakePool.getPool().acquire().then((conn: snowflake.Connection): snowflake.Connection => { this.logger.debug('* SNOWFLAKE CONNECTED * Successfully connected as id: ' + conn.getId()); return conn; }).catch((error) => { this.logger.errorWithStack('* SNOWFLAKE ERROR * Unable to connect.', error); if (new Error(error).message.toLowerCase().includes(this.AUTHENTICATION_ERROR_MESSAGE.toLowerCase())) { this.connectionErrorCode = this.AUTHENTICATION_ERROR_CODE; } return false; });

we use the connection to perform the query and then we release it to the pool by doing this
return global.snowflakePool.getPool().release(this.connection).then(() => { logger.debug('** SNOWFLAKE RELEASED CONNECTION ** Id: ' + this.connection.getId()); this.connection = undefined; resolve(); }).catch((error) => { logger.error('** SNOWFLAKE RELEASE CONNECTION ERROR ** Failed to release Id: ' + this.connection.getId() + ' ' + error); resolve(); });

with global.snowflakePool.getPool() we just retrieve the global variable that contains the pool

@sfc-gh-dszmolka
Copy link
Collaborator

thank you for the snippet ! this looks like the expected behaviour.

since the connection is still open and established and ready to receive queries over it (the main reason for using Connection Pool in the first place; to avoid the overhead needed to repeatedly re-establish the Connection), I think it's expected that the Snowflake Session is still alive which session is associated with the connection which was never closed.

as the documentation linked above

Snowflake recommends reusing existing sessions when possible and to close the connection to Snowflake when a session is no longer needed.

if a Connection wasn't closed, we don't expect* the associated Snowflake Session to be closed on the server end.
*session policies apply, by default, authentication token valid for 4 hours

you might want to consider calling snowflakePool.destroy instead or calling the Snowflake-specific Connection.destroy as mentioned above.

is this something which could work for you ?

@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage_done Initial triage done, will be further handled by the driver team and removed status-triage Issue is under initial triage status-information_needed Additional information is required from the reporter labels Mar 4, 2024
@Lumengrid
Copy link
Author

thank you for the snippet ! this looks like the expected behaviour.

since the connection is still open and established and ready to receive queries over it (the main reason for using Connection Pool in the first place; to avoid the overhead needed to repeatedly re-establish the Connection), I think it's expected that the Snowflake Session is still alive which session is associated with the connection which was never closed.

as the documentation linked above

Snowflake recommends reusing existing sessions when possible and to close the connection to Snowflake when a session is no longer needed.

if a Connection wasn't closed, we don't expect* the associated Snowflake Session to be closed on the server end. *session policies apply, by default, authentication token valid for 4 hours

you might want to consider calling snowflakePool.destroy instead or calling the Snowflake-specific Connection.destroy as mentioned above.

is this something which could work for you ?

yes I think so, TY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

2 participants