johnnadratowski / golang-neo4j-bolt-driver

Golang Bolt driver for Neo4j
MIT License
213 stars 72 forks source link

[bug] Connection retries #39

Closed caub closed 6 years ago

caub commented 6 years ago

I tried to make this driver retry to connect, until the connection is up

but it's freezing

func NewDriverPool(user string, host string, max int) (neo4j.DriverPool, error) {
    // neo4j.DriverPool
    DB, err := neo4j.NewDriverPool("bolt://"+user+"@"+host, max)
    if err != nil {
        return nil, err
    }
    retries := 0
    // try to get a neo4j.Connc
    for retries < 300 {
        // it's not working yet, when a neo4j connection is up
        // it's waiting here, without polling anymore
        conn, err := DB.OpenPool()
        fmt.Println("OpenPool", conn, err)
        if conn != nil {
            return DB, nil
        }
        retries = retries + 1
        log.Warn("neo4j not ready, waiting 1s and trying again ", retries)
        time.Sleep(1 * time.Second)
    }
    return nil, err
}

When launching neo4j, the loop stops, but doesn't return, I guess it's a bug somewhere in this driver

If I start the server after neo4j is up, it works fine

WARN[0072] neo4j not ready, waiting 1s and trying again 73 
OpenPool <nil> An error occurred dialing to neo4j
Internal Error(*net.OpError):dial tcp 127.0.0.1:7687: getsockopt: connection refused

 Stack Trace:

goroutine 1 [running]:
runtime/debug.Stack(0x85103d, 0x22, 0x0)
    /usr/lib/go-1.8/src/runtime/debug/stack.go:24 +0x79
github.com/johnnadratowski/golang-neo4j-bolt-driver/errors.Wrap(0x9f8960, 0xc4202c0140, 0x85103d, 0x22, 0x0, 0x0, 0x0, 0x9f8960)
    /home/caub/go/src/github.com/johnnadratowski/golang-neo4j-bolt-driver/errors/errors.go:38 +0x1ad
github.com/johnnadratowski/golang-neo4j-bolt-driver.(*boltConn).createConn(0xc42018cd20, 0xc4201fe000, 0x4, 0x0, 0xc4200001a0)
    /home/caub/go/src/github.com/johnnadratowski/golang-neo4j-bolt-driver/conn.go:193 +0x2a4
github.com/johnnadratowski/golang-neo4j-bolt-driver.(*boltConn).initialize(0xc42018cd20, 0xc420187a40, 0xc420171c20)
    /home/caub/go/src/github.com/johnnadratowski/golang-neo4j-bolt-driver/conn.go:278 +0x481
github.com/johnnadratowski/golang-neo4j-bolt-driver.(*boltDriverPool).OpenPool(0xc420154b40, 0x0, 0x0, 0x0, 0x0)
    /home/caub/go/src/github.com/johnnadratowski/golang-neo4j-bolt-driver/driver.go:131 +0x150
main.NewDriverPool(0x85015a, 0x20, 0x85015a, 0x20, 0x85015a, 0x20)
    /home/caub/dev/neo4j-srv/util.go:53 +0x2e7
main.(*App).Initialize(0xa2da00)
    /home/caub/dev/neo4j-srv/app.go:67 +0xeb
main.main()
    /home/caub/dev/neo4j-srv/start.go:37 +0x5b

WARN[0073] neo4j not ready, waiting 1s and trying again 74 
umsu2 commented 6 years ago

encountered the exact problem, made a pull request which should fix it. let me know if works for you.

scott-wilson commented 6 years ago

@caub This still a problem for you after the fix from @umsu2?

caub commented 6 years ago

Sorry, I can't really test, I'm not working anymore on this go + neo4j project

let's assume it's fixed, and reopen if not