Closed
Description
I've tried to use reconnect to wait for tarantool
started with Go to bootstrap, but it doesn't work.
init.lua
box.cfg{}
box.schema.user.grant('guest', 'execute', 'universe', nil, { if_not_exists = true })
box.cfg{ listen = 3301 }
main.go
package main
import (
"log"
"os/exec"
"time"
"github.com/tarantool/go-tarantool"
)
func main() {
// Prepare tarantool command
cmd := exec.Command("tarantool", "init.lua")
// Start tarantool.
err := cmd.Start()
if err != nil {
log.Panic("Failed to start: ", err)
}
defer cmd.Process.Kill()
// Uncomment to wait explicitly.
// time.Sleep(200 * time.Millisecond)
// Try to connect and ping tarantool.
var opts = tarantool.Opts{
Timeout: 500 * time.Millisecond,
User: "guest",
Pass: "",
MaxReconnects: 5,
Reconnect: 200 * time.Millisecond,
SkipSchema: true,
}
conn, cerr := tarantool.Connect("127.0.0.1:3301", opts)
if cerr != nil {
log.Panic("Failed to connect: ", cerr)
}
if conn == nil {
log.Panic("Conn is nil after connect")
}
defer conn.Close()
resp, rerr := conn.Ping()
if rerr != nil {
log.Panic("Failed to ping: ", rerr)
}
if resp == nil {
log.Panic("Response is nil after ping")
}
}
Run
go mod init example
go mod tidy
go run .
2022/01/17 13:06:53 Failed to ping: client connection is not ready (0x4000)
panic: Failed to ping: client connection is not ready (0x4000)
goroutine 1 [running]:
log.Panic({0xc00013dec8, 0xbebc200, 0x5})
/usr/local/go/src/log/log.go:354 +0x65
main.main()
/home/georgymoiseev/Development/sandbox/goreconnect/main.go:45 +0x313
exit status 2
Run (uncomment time.Sleep)
go mod init example
go mod tidy
go run .
# ok
So either I do it wrong (for example, looks like it shouldn't work without SkipSchema: true
, but it isn't enough):
Lines 193 to 194 in 9c9a68e
or it is broken.