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

SDK can't restore connection after disconnection #22

Open
dimuska139 opened this issue Apr 26, 2022 · 4 comments
Open

SDK can't restore connection after disconnection #22

dimuska139 opened this issue Apr 26, 2022 · 4 comments

Comments

@dimuska139
Copy link

dimuska139 commented Apr 26, 2022

SDK can't restore connection after disconnection

package main

import "github.com/manticoresoftware/go-sdk/manticore"
import "fmt"

func main() {
	cl := manticore.NewClient()
	cl.SetServer("127.0.0.1", 9311)
	_, err := cl.Open()
	if err != nil {
		fmt.Println(err)
	}
	for ;; {
		search := manticore.NewSearch("аватар", "idx_movies", "")
		search.Limit = 10
		res, err := cl.RunQuery(search)
		if err != nil {
			fmt.Println(err)
			continue
		}
		for _, item := range res.Matches {
			fmt.Println(item.Attrs[0])
		}
	}
}

Just run this sample, make sure the results start showing up and restart manticore after few seconds. The connection will not be restored and the program will continue to give an error (write tcp 127.0.0.1:49914->127.0.0.1:9311: write: broken pipe) despite the fact that the Manticore is already available

@dimuska139 dimuska139 reopened this Apr 26, 2022
@dimuska139 dimuska139 changed the title SDK can't reconnect after disconnection SDK can't restore connection after disconnection Apr 26, 2022
@sanikolaev
Copy link
Contributor

I'm not a go developer, but curious: is it different in case of other databases? E.g. mysql, elasticsearch? I mean it is it a common practice at all to restore a connection?

@dimuska139
Copy link
Author

@sanikolaev the same example with using MySQL driver works as expected (driver not closes connection after error):

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

func main() {
	db, err := sql.Open("mysql", "tcp(127.0.0.1:9366)/")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	for ;; {
		results, err := db.Query("SELECT name FROM idx_movies WHERE MATCH('аватар') limit 10 offset 0")
		if err != nil {
			fmt.Println(err)
			continue
		}
		for results.Next() {
			var name string
			_ = results.Scan(&name)
			log.Printf(name)
		}
	}
}

@sanikolaev
Copy link
Contributor

Interesting how it's implemented in the mysql driver? At first glance I can only see https://github.com/go-sql-driver/mysql/blob/master/statement.go#L101 :

func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
	return stmt.query(args)
}

func (stmt *mysqlStmt) query(args []driver.Value) (*binaryRows, error) {
...
	if stmt.mc.closed.IsSet() {
		errLog.Print(ErrInvalidConn)
		return nil, driver.ErrBadConn
	}

nothing like a connection restore upon a failed request or any other kind of retry.

@dimuska139
Copy link
Author

@sanikolaev database/sql opens new connection if driver returns driver.ErrBadConn after two attempts. https://github.com/golang/go/blob/master/src/database/sql/sql.go#L1716

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

No branches or pull requests

2 participants