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

support for session_timeout parameter #370

Open
otan opened this issue Jan 1, 2025 · 4 comments
Open

support for session_timeout parameter #370

otan opened this issue Jan 1, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@otan
Copy link

otan commented Jan 1, 2025

Use case

Using temporary tables, our jobs (unfortunately) can have a long delay sometimes that requires a session to be idle for a while.

The docs make mention of default_session_timeout and session_timeout: https://clickhouse.com/docs/en/interfaces/http.

Similarly, you can use ClickHouse sessions in the HTTP protocol. To do this, you need to add the session_id GET parameter to the request. You can use any string as the session ID. By default, the session is terminated after 60 seconds of inactivity. To change this timeout, modify the default_session_timeout setting in the server configuration, or add the session_timeout GET parameter to the request. To check the session status, use the session_check=1 parameter. Only one query at a time can be executed within a single session.

However, I cannot find session_timeout on the client.
I also cannot find where to modify default_session_timeout on the server config for ClickHouse cloud as it does not exist in system.settings.

Describe the solution you'd like

Exposing session_timeout in the client is most ideal.

Describe the alternatives you've considered

Not sure any besides writing our own http client.

Additional context

@otan otan added the enhancement New feature or request label Jan 1, 2025
@otan otan changed the title support for [default_]session_timeout support for session_timeout parameter Jan 1, 2025
@slvrtrn
Copy link
Contributor

slvrtrn commented Jan 3, 2025

I think it should work if you just put it to clickhouse_settings, e.g.

const rs = client.query({
  query: 'SELECT ...',
  clickhouse_settings: {
    session_timeout: 3600,
    session_check: 1,
  }
})

@slvrtrn
Copy link
Contributor

slvrtrn commented Jan 3, 2025

@otan
Copy link
Author

otan commented Jan 3, 2025

would need to disable lint if it exist in typescript, but will give it a shot. is the unit seconds or milliseconds?

off note: not sure where to drop this feedback, but it'd be a lot easier if you treat "sessions" differently to the ClickhouseClient object to creating a client with max_open_connections: 1. something like:

const clickhouse = new clickhouseClient({...});
const clickhouseClientPoolSession = clickhouse.session({session_id: blah});
try {
  // use clickhouseClientPoolSession so it doesn't return to a pool etc.
} finally {
   clickhouseClientPoolSession.close();
}

@slvrtrn
Copy link
Contributor

slvrtrn commented Jan 3, 2025

would need to disable lint if it exist in typescript, but will give it a shot.

TS compiler shouldn't complain, see Record here:

export type ClickHouseSettings = Partial<ClickHouseServerSettings> &
Partial<ClickHouseHTTPSettings> &
Record<string, number | string | boolean | SettingsMap | undefined>

is the unit seconds or milliseconds?

it's in seconds: https://github.com/ClickHouse/ClickHouse/blob/fe35e6d3def4c73755e7bd20b65ebe2a2e0a52a4/src/Server/HTTPHandler.cpp#L126-L148

See also: https://github.com/ClickHouse/ClickHouse/blob/fe35e6d3def4c73755e7bd20b65ebe2a2e0a52a4/programs/server/config.xml#L997-L998

the docs should be updated, it's not 100% clear from there.

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

No branches or pull requests

2 participants