Skip to content

Ping() does not validate connectivity for remote URLs #76

@ashmortar

Description

@ashmortar

Ping() does not validate connectivity for remote URLs

When using remote database URLs (libsql://, https://, http://), the Ping() method always returns success, even when the host is unreachable. This makes it impossible to validate database connectivity during application startup or health checks.

Reproduction

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/tursodatabase/go-libsql"
)

func main() {
    // Non-existent host
    db, err := sql.Open("libsql", "libsql://unreachable-host.invalid?authToken=test")
    if err != nil {
        panic(err)
    }
    defer db.Close()
    
    // Should fail but returns nil
    err = db.Ping()
    fmt.Printf("Ping error: %v\n", err)  // Output: Ping error: <nil>
    
    // Actual failure only occurs when executing queries
    var result int
    err = db.QueryRow("SELECT 1").Scan(&result)
    fmt.Printf("Query error: %v\n", err)
    // Output: Query error: failed to execute query SELECT 1
    // error code = 1: Error executing statement: Hrana: `http error: `error trying to connect: dns error: failed to lookup address information: Name or service not known``
}

Expected Behavior

Ping() should attempt to establish a connection and return an error if the host is unreachable, following the standard database/sql driver behavior.

Current Behavior

The connection is only attempted when executing statements. Open(), Ping(), and even Conn() all succeed without validating connectivity.

Impact

Applications cannot:

  • Validate database configuration at startup
  • Implement proper health checks
  • Fail fast on misconfigured connection strings

Suggested Fix

Implement the driver.Pinger interface to validate connectivity for remote URLs, or at minimum execute a simple query like SELECT 1 during Ping() to ensure the database is reachable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions