Handshake is setting DialTimeout instead of context deadline#1709
Handshake is setting DialTimeout instead of context deadline#1709NamanMahor wants to merge 14 commits intoClickHouse:mainfrom
Conversation
|
@NamanMahor thanks for the PR :). I know it's a simple change. can you please add tests for this to avoid any regression in the future? |
|
@kavirajk sure will add the test. I have one question which could also be bug. we are overriding the ctx with timeout/deadline here https://github.com/ClickHouse/clickhouse-go/blob/main/clickhouse.go#L304 which is being used by |
The way I see it, we have i'm curious what is your use case here?. You trying to set this timeout more dynamically only on the |
|
@kavirajk sorry about late response totally miss this one. I have added the test. |
|
@kavirajk can you please have a look i have added the tests. |
At Rill, users configure ClickHouse connections through a UI where they provide the host, port, and other connection details. We commonly see two scenarios: The user enters a hostname that is valid but not actually running ClickHouse. The ClickHouse cluster is in a hibernated state and takes time to wake up. To handle the hibernation case, we need to increase the read timeout so the handshake can wait long enough for the cluster to wake up. However, if we also increase the dial timeout, then the first scenario (wrong host) ends up waiting for the full dial timeout before failing, which leads to a poor user experience. Ideally, we want the TCP dial to fail fast when the host is incorrect, while still allowing the handshake to wait longer when the cluster is waking up. If the dial context isn’t reused for the handshake, the handshake can use the user-provided context (which has the longer timeout), and we don’t have to increase the dial timeout. This allows wrong-host cases to fail quickly while still supporting clusters that take longer to respond during handshake. |
Summary
If a user provides a context.Context with a timeout, it is ignored here in conn_handshake.go even though comment is correct to set
context level deadline override any read deadlinebut instead of deadline we are setting Dialtimeout.Made change to handle context deadline as we are already doing in here in conn_ping.go