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

fix panic when passing nil to time.Time.In() #1100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

madisonchamberlain
Copy link
Contributor

@madisonchamberlain madisonchamberlain commented Apr 15, 2024

Description

SNOW-XXX Please explain the changes you made here.
When time.Time.In is used, if a nil is passed in it will panic. (See docs) In the other functions in converter.go (see stringToValue timestamp_ltz) if the loc is nil a default will be used.

  • Bug was introduced in this pr

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

@madisonchamberlain madisonchamberlain requested a review from a team as a code owner April 15, 2024 20:37
Comment on lines +674 to 676
if scd.sc != nil && scd.sc.cfg != nil {
return getCurrentLocation(scd.sc.cfg.Params)
}

Choose a reason for hiding this comment

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

is it possible that Params is empty or something that will return a bad value for time.Location?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if getCurrentLocation is called something non nil will be returned, updated the else option to also return time.Now.Location so we dont ever return nil

converter.go Outdated
Comment on lines 319 to 321
if loc == nil {
loc = time.Now().Location()
}

Choose a reason for hiding this comment

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

should these just be time.Location? i.e. avoid the Now() call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

afaik time.Location{} if not generated by time.Now() is an empty struct which will panic without the name string

Copy link
Collaborator

Choose a reason for hiding this comment

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

loc is initialized two lines above - so this condition is always false, am I right?

@@ -671,10 +671,10 @@ type snowflakeArrowStreamChunkDownloader struct {
}

func (scd *snowflakeArrowStreamChunkDownloader) Location() *time.Location {
if scd.sc != nil {
if scd.sc != nil && scd.sc.cfg != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is not a mistake, but I'm wondering - you actually encountered this situation? By looking at the code I can see that when snowflakeConn is initialised, it is always initialised with not nil config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not experienced this, I can remove it I just wanted to ensure that we dont null pointer dereference in any possible way

return getCurrentLocation(scd.sc.cfg.Params)
}
return nil
return time.Now().Location()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly - looking at the code, we should never reach this line, scd.sc is always initalised...

This line is much more tricky anyway. This location may be completely different than snowflake session timezone, meaning it may break LTZ contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we should never hit this line but it seems that we are hitting it. I personally feel like this is a good temporary fix until we figure out why the connection is nil because having a panic seems worse to me but I am open to any other solutions

converter.go Outdated
Comment on lines 319 to 321
if loc == nil {
loc = time.Now().Location()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

loc is initialized two lines above - so this condition is always false, am I right?

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

Successfully merging this pull request may close these issues.

None yet

3 participants