databricks / databricks-sql-go

Golang database/sql driver for Databricks SQL.
Apache License 2.0
34 stars 38 forks source link

pinging: driver: bad connection #161

Closed achettyiitr closed 6 months ago

achettyiitr commented 9 months ago
func TestDatabricks(t *testing.T) {
    const (
        host      = "xxx"
        port      = 443
        path      = "xxx"
        token     = "xxx"
        userAgent = "xxx"
        catalog   = ""
    )

    connector, err := dbsql.NewConnector(
        dbsql.WithServerHostname(host),
        dbsql.WithPort(port),
        dbsql.WithHTTPPath(path),
        dbsql.WithAccessToken(token),
        dbsql.WithSessionParams(map[string]string{
            "ansi_mode": "false",
        }),
        dbsql.WithUserAgentEntry(userAgent),
        dbsql.WithInitialNamespace(
            catalog,
            "",
        ),
        dbsql.WithTimeout(time.Second*15),
        dbsql.WithRetries(10, 1*time.Second, 300*time.Second),
    )
    require.NoError(t, err)

    db := sql.OpenDB(connector)
    defer func() { _ = db.Close() }()

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
    defer cancel()

    err = db.PingContext(ctx)
    require.NoError(t, err)
}

Issue: Getting driver bad connection, while calling Ping with ContextWithTimeout. Although, it's not reproducible. There is some edge case happening when the cluster is starting and we are executing Query. Driver Version: v1.1.0 Expectation: To return the error instead of DriverBadConnection.

Screenshot 2023-09-19 at 10 51 44 PM (2) Screenshot 2023-09-19 at 10 50 29 PM

rcypher-databricks commented 9 months ago

Thanks for raising this issue. We will look into a change.

rcypher-databricks commented 8 months ago

In version 1.5.1 we are now wrapping the causative error in a bad connection error. You can use errors.Is/As to check for timeout, cancellation, etc.

rcypher-databricks commented 7 months ago

Has the fix in 1.5.1 resolved this issue for you?