Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session.IsConnected not detecting disconnection #472

Open
arsssen opened this issue Feb 3, 2020 · 8 comments
Open

Session.IsConnected not detecting disconnection #472

arsssen opened this issue Feb 3, 2020 · 8 comments

Comments

@arsssen
Copy link

arsssen commented Feb 3, 2020

When a session loses connection, the Term.Run returns ErrConnectionClosed error, however
the Session.IsConnected method still reports that connection is alive (even after the failed Run).

@CMogilko
Copy link
Member

CMogilko commented Feb 4, 2020

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.

@arsssen
Copy link
Author

arsssen commented Feb 4, 2020

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) .

@arsssen
Copy link
Author

arsssen commented Mar 10, 2020

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
...

@arsssen
Copy link
Author

arsssen commented Mar 10, 2020

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)

@CMogilko
Copy link
Member

Hi, should be fixed in 6.2.0

@arsssen
Copy link
Author

arsssen commented Mar 19, 2020

Hi, just tested 6.2.1 with the same code (#472 (comment)) , 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.

@tubi89
Copy link

tubi89 commented Jul 25, 2020

Hello, I want to develop a project with the Betconstruct API. Do you have any projects? Thank you

@xlargeFame
Copy link

Merhaba, Betconstruct API ile proje geliştirmek istiyorum. Herhangi bir projeniz var mı? Teşekkür ederim

Did you find the example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants