Open arsssen opened 4 years ago
Hello,
Session.IsConnnected
reports if any nodes are connected, not particularly that failed query. Anyway, between Term.Run
and Session.IsConnected
connection can be reconnected. And connections also are pooled.
What I was trying to achieve was checking connection before trying to run the query, but I guess it's better to check for Run
errors and retry in case of ErrConnectionClosed
.
Btw, Session.IsConnected
reports that connection is alive even after shutting down the rethinkdb server (there's a single server, no cluster) .
Hello,
I've done some more testing, it turns out Session.IsConnected
never returns false once connected.
here's a sample code to check (run it, then shut down rethinkdb server):
package main
import (
"fmt"
"time"
"gopkg.in/rethinkdb/rethinkdb-go.v6"
)
func main() {
session, _ := rethinkdb.Connect(rethinkdb.ConnectOpts{
Address: "localhost:28015", InitialCap: 1, MaxOpen: 1})
for {
_, err := session.Server()
fmt.Printf("err:%s connected:%t\n", err, session.IsConnected())
time.Sleep(time.Second)
}
}
the output is:
err:%!s(<nil>) connected:true
err:%!s(<nil>) connected:true
err:rethinkdb: the connection is closed connected:true
err:rethinkdb: the connection is closed connected:true
err:rethinkdb: the connection is closed connected:true
...
Also looked at the code, seems like session.IsConnected
relies on len(Cluster.GetNodes())
, but nodes are never removed ( Cluster.removeNode
is not used anywhere in the code)
Hi, should be fixed in 6.2.0
Hi, just tested 6.2.1 with the same code (https://github.com/rethinkdb/rethinkdb-go/issues/472#issuecomment-596958554) , only the error message has changed, now it's dial tcp 127.0.0.1:28015: connect: connection refused
instead of rethinkdb: the connection is closed
, but IsConnected
still returns true
.
Hello, I want to develop a project with the Betconstruct API. Do you have any projects? Thank you
Merhaba, Betconstruct API ile proje geliştirmek istiyorum. Herhangi bir projeniz var mı? Teşekkür ederim
Did you find the example?
When a session loses connection, the
Term.Run
returnsErrConnectionClosed
error, however theSession.IsConnected
method still reports that connection is alive (even after the failedRun
).