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-892592: Fix panic when SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED=false #883

Closed

Conversation

sfc-gh-ext-simba-lb
Copy link
Contributor

@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb commented Aug 14, 2023

Description

https://github.com/snowflakedb/snowflake-sdks-drivers-issues-teamwork/issues/608
When testing for https://github.com/snowflakedb/snowflake-sdks-drivers-issues-teamwork/issues/593 I found a panic when SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED is false. The initOcspCache() function initializes a mutex lock on the ocsp response cache. If SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED=false it exits the init function before the lock is initialized. The driver tries to access it later and it causes a panic during connection.

This change is to initialize the lock first and then check for SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED.

Checklist

  • Code compiles correctly
  • Run make fmt to fix inconsistent formats
  • Run make lint to get lint errors and fix all of them
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb force-pushed the fixPanicWithOcspCacheServerDisabled branch from 340f230 to 74f04e1 Compare August 14, 2023 23:29
@sfc-gh-ext-simba-lb sfc-gh-ext-simba-lb force-pushed the fixPanicWithOcspCacheServerDisabled branch from 74f04e1 to b36df6c Compare August 15, 2023 15:44
func TestCacheServerDisabled(t *testing.T) {
_ = os.Setenv(cacheServerEnabledEnv, "false")

if _, err := buildSnowflakeConn(context.Background(), Config{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can extract building sf conn outside of the if? Or at least Config? Now it's not very readable.

}

ocspURL := os.Getenv(cacheServerURLEnv)
if ocspURL != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if I understand it. According to the first line in the test, you just set an env variable and now you read another one. I believe this just reads env variable, there is no driver logic. The only reason why this could work is that buildSnowflakeConn removes this env var, which seems unlike. But if this should work, maybe we should enrich the test with setting cacheServerUrlEnv at the beginning of the test?

@sfc-gh-ext-simba-jl
Copy link
Collaborator

Closing this PR since I can't reproduce the original issue.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2023
@sfc-gh-pfus sfc-gh-pfus deleted the fixPanicWithOcspCacheServerDisabled branch December 5, 2023 11:23
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.

3 participants