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-551650: Is the parameter cfg.KeepSessionALive useless in HeartBeat? #556

Closed
kchojn opened this issue Feb 24, 2022 · 6 comments
Closed
Assignees
Labels

Comments

@kchojn
Copy link

kchojn commented Feb 24, 2022

Issue description

I was wondering why I keep getting the message Authentication token has expired, even if I've set KeepSessionAlive as True in the config.
Analyzing the code, I see that it is not parsed and used anywhere. The keep session alive parameter is taken from Params. Also I see that heartBeat is based on params:
Edit: I'm using dsn

func (sc *snowflakeConn) isClientSessionKeepAliveEnabled() bool {
	v, ok := sc.cfg.Params[sessionClientSessionKeepAlive]
	if !ok {
		return false
	}
	return strings.Compare(*v, "true") == 0
}

Should I only use params for additional settings then?

Example code

func getDSN() (string, *sf.Config, error) {
	cfg := &sf.Config{
		Account:          setting.DatabaseSetting.Account,
		User:             setting.DatabaseSetting.User,
		Password:         setting.DatabaseSetting.Password,
		Database:         setting.DatabaseSetting.Database,
		Schema:           setting.DatabaseSetting.Schema,
		Warehouse:        setting.DatabaseSetting.Warehouse,
		Role:             setting.DatabaseSetting.Role,
		Region:           setting.DatabaseSetting.Region,
		KeepSessionAlive: true,
	}
	dsn, err := sf.DSN(cfg)
	return dsn, cfg, err
}

Error log

time="2022-02-24T07:28:45Z" level=error msg="error: 390114: Authentication token has expired.  The user must authenticate again." func="gosnowflake.(*snowflakeConn).queryContextInternal" file="connection.go:338"

Configuration

Driver version (or git SHA): latest

Go version: go1.17.6 linux/amd64

Server version: 6.4.1

Client OS:

Ubuntu 18.04.6 LTS

@github-actions github-actions bot changed the title Is the parameter cfg.KeepSessionALive useless? SNOW-551650: Is the parameter cfg.KeepSessionALive useless? Feb 24, 2022
@kchojn kchojn changed the title SNOW-551650: Is the parameter cfg.KeepSessionALive useless? SNOW-551650: Is the parameter cfg.KeepSessionALive useless in HeartBeat? Feb 24, 2022
@kchojn
Copy link
Author

kchojn commented Feb 24, 2022

Looks like client keep seesion alive param is not working either

params["client_keep_session_alive"] = clientKeepSessionAlive

4 hours later:

time="2022-02-24T14:09:09Z" level=error msg="error: 390114: Authentication token has expired.  The user must authenticate again." func="gosnowflake.(*snowflakeConn).queryContextInternal" file="connection.go:338"

I also do not see the execution of select 1 in the history panel. Only after running.

This is how db is created:

func Setup() {
	dsn, _, err := getDSN()
	if err != nil {
		log.Fatal(err)
	}
	db, err := sql.Open("snowflake", dsn)
	if err != nil {
		log.Fatalf("SnowFlake setup err: %v", err)
	}

	err = db.Ping()
	if err != nil {
		log.Fatalf("SnowFlake ping err: %v", err)
	}

	db.SetMaxIdleConns(10)
	db.SetMaxOpenConns(100)

	Db = db
}

@sfc-gh-wfateem sfc-gh-wfateem self-assigned this Mar 4, 2022
@sfc-gh-wfateem
Copy link
Collaborator

Hi @kchojn,
I think you might have swapped parts of the name, it should be client_session_keep_alive not client_keep_session_alive, and you can set that in the DSN.

@kchojn
Copy link
Author

kchojn commented Mar 4, 2022

Hey @sfc-gh-wfateem ,
Thank you for your time and response. I agree, I made a mistake 😳 It seems to be working now!

What about config attr KeepSessionAlive? Does it have any use?

@sfc-gh-wfateem
Copy link
Collaborator

Hey @kchojn,

I think what we're interested in is sessionClientSessionKeepAlive, but I do agree, KeepSessionAlive doesn't look like it has much use after skimming through the code briefly. Not sure what the history is behind that portion of the code. I'll look into it a bit and ask someone else who's a bit more familiar with this codebase in case there's some cleanup that needs to happen.
Concerning your issue though, are you good with using the option provided (client_session_keep_alive)?

@kchojn
Copy link
Author

kchojn commented Mar 4, 2022

@sfc-gh-wfateem, yes, I'm good with that! Thank you. This config attr KeepSessionAlive was misleading, for me.
I will open pr with the usage of this parameter.
From my side everything is clear, feel free to close the issue if you want.

Regards!

@sfc-gh-wfateem
Copy link
Collaborator

All right then, thanks for reaching out @kchojn! Have a good one!

mihaitodor added a commit to mihaitodor/connect that referenced this issue Nov 3, 2022
This is an attempt to prevent the Snowflake connection from
becoming invalid after 4 hours as described [here](snowflakedb/gosnowflake#556).

The change is inspired from [this example](https://github.com/snowflakedb/gosnowflake/blob/82aecfae87c571aa7dfe1c7542e1e48517e79ec8/cmd/keepalive/keepalive.go#L37-L53) in the github.com/snowflakedb/gosnowflake code.

Fixes redpanda-data#1556.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants