schwartzmx / gremtune

Golang Gremlin Tinkerpop client with AWS Neptune compatibility
MIT License
26 stars 19 forks source link

How should I recover when the client lost the connection? #5

Closed provCristianMaluenda closed 5 years ago

provCristianMaluenda commented 5 years ago

Hi, Every time that my service lost the connection with Gremlin, the service throws an error and exit.

How can I recover my service after the WebSocket is closed? I thought using Pool will solve the problem but it doesn't. I don't know if I am doing something wrong.

Here is my PooledConnection:

       errs := make(chan error)
    go func(chan error) {
        err := <-errs
        log.Fatal("Lost connection to the database: " + err.Error())
    }(errs)

    pool := &gremtune.Pool{MaxActive: 10, Dial:func()(*gremtune.Client, error){
        dialer := gremtune.NewDialer(uri)
        c, err := gremtune.Dial(dialer, errs) 
        return &c, err}}
    pc := pool.Get()
        rsp, err := pc.Client.Execute(query)

The error is: write tcp 127.0.0.1:58211->127.0.0.1:8182: write: broken pipe

Thanks

schwartzmx commented 5 years ago

I will have to make a test for this to reproduce and will get back to you.

Just to note you shouldn't need to directly do pc := pool.Get() you can just do pool.Execute(query)

Also is that the full panic trace? If not can you post the entire thing so I can try to trace back to where the client is not catching and re dialing a new connection.

provCristianMaluenda commented 5 years ago

Thanks for your help.

Sadly, there is not a panic trace. I only the message 2019/10/01 11:26:54 Lost connection to the database: write tcp 127.0.0.1:60044->127.0.0.1:8182: write: broken pipe.

The error happens when my service lost the connection after response to some requests. If the service doesn't get any request, it is not a problem. For testing and development, I am using Gremlin Server.

Regards, Cristian.

provCristianMaluenda commented 5 years ago

Never mind, I found the problem. It was my code (I am new in Golang). The example was confused how it handles the errors:

go func(chan error) {
        err := <-errs
        log.Fatal("Lost connection to the database: " + err.Error())
    }(errs) // Example of connection error handling logic

The issue was, log.Fatal() write a log and then calls os.Exit(1).

schwartzmx commented 5 years ago

Ah, yeah sorry about that. I should re-assess the existing docs.