Skip to content

db.Open does not fail when there is no server [moved] #7

Closed
@julienschmidt

Description

@julienschmidt

This is Issue 7 moved from a Google Code project.
Added by 2012-06-23T21:09:10.000Z by elij...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.
Closed (WontFix).

Original labels: Type-Defect, Priority-High, OpSys-OSX

Original description

<b>Problem summary:</b>

Not sure if this is something particular to my system or if I am using the driver incorrectly, but when I call something similar to the following code with the mysql server shut off, it does not return an err:

    import (
        &quot;log&quot;
    &quot;database/sql&quot;
    _ &quot;code.google.com/p/go-mysql-driver/mysql&quot;
    )

    var database *sql.DB
    func main() {
        db, err := sql.Open(&quot;mysql&quot;, dsn)
        if err != nil {
            log.Fatal(&quot;Could not connect to:&quot;, k)
        }
        database = db
                // database later is accessed by various goroutines
                doMuchWorkHere()
   }

I am running the mysql server locally. Dsn similar to &quot;user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8&keepalive=1&quot;

I considered using db.Driver() to get the underlying driver and maybe using mc.Ping myself to test, but the documentation for database/sql seems to imply that Open would return a failure on setup if the server could not be contacted.

I thought maybe it was due to net.Dial being used instead of net.DialTimeout, but I am not sure.

Am I using the driver wrongly by expecting open to return an error if the server is down or it cannot be contacted?

Used go-mysql-version:
  changeset:   27:2c2c693701e6
  tag:         tip
  user:        Julien Schmidt
  date:        Wed May 30 16:00:01 2012 +0200

MySQL-Server version: mysql 5.5.25
Used Operation System: osx 10.7.4
Go version: go version go1.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions