nebula go client 链接失败

github.com/vesoft-inc/nebula-go v1.1.1-0.20210107092414-84e65ea23b79

Fail to create a new session from connection pool, username: xxx, password: xxx, Authentication fails, read tcp 172.28.64.1:59828->172.28.77.33:9669: use of closed ne
twork connection

你好,请提供一下nebula服务的版本以及链接池的config。另外从版本上看这个不是最新的go client,可以更新一下再试试。

go get -u -v github.com/vesoft-inc/nebula-go@release-v2.0.0-rc1 这个release-v2.0.0-rc1我换成master下下来的也是v1.1.1的版本


连接池config是什么
const (
address = “127.0.0.1”
port = 9669
username = “user”
password = “password”
)
这个吗

v1.1.1是github自动给的命名,我是根据日期看出客户端不是最新的,不过只要你的nebula服务和客户端都是rc1的release保持一致就没问题。
链接池配置是一个struct结构,创建链接池时需要的,可以的话能贴下你怎么调用客户端的吗,另外从报错看是用户验证失败,你在服务端开启验证了吗?
Screen Shot 2021-03-17 at 5.48.08 PM

docker run --rm -ti --network nebula-docker-compose_nebula-net --entrypoint=/bin/sh vesoft/nebula-console:v2-nightly

nebula-console -u tzb -p 123456 --address=graphd --port=9669
这是我服务端的运行

下面是客户端代码,看了下你说的那个config用的是默认的
hostAddress := nebula.HostAddress{Host: address, Port: port}
hostList := []nebula.HostAddress{hostAddress}
// Create configs for connection pool using default values
testPoolConfig := nebula.GetDefaultConf()

// Initialize connection pool
pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, nebulaLog)
if err != nil {
nebulaLog.Fatal(fmt.Sprintf(“Fail to initialize the connection pool, host: %s, port: %d, %s”, address, port, err.Error()))
}

const (
	address  = "127.0.0.1"
	port     = 9669
	username = "tzb"
	password = "123456"
)

试一下把客户端内的账户密码改成你起服务的 -u tzb -p 123456

const (
address = “172.28.77.33”
port = 9669
username = “tzb”
password = “123456”
)
就是用的这个,不行

你用的镜像是每天更新的nightly,和客户端版本没对上,用 go get -u -v github.com/vesoft-inc/nebula-go@master 把客户端也更新到最新试试

v1.1.1-0.20210310115345-e698c73b5354
换了,还是一样的错

把 address换成graphd呢

没太懂应该怎么换呢?

const (
	address  = "graphd"
	port     = 9669
	username = "tzb"
	password = "123456"
)

服务的验证默认是关闭的,那么错误和用户密码无关

Fail to initialize the connection pool, host: graphd, port: 9669, Failed to find IP, error: lookup graphd: no such host

const (
    address = “172.28.77.33”
    port = 9669
    username = “tzb”
    password = “123456”
)

在用这份配置时,有报出Fail to initialize the connection pool, host的错误吗?能确定下当时服务的状态吗?

没有,是这个

connection pool is initialized successfully

能贴一下graph的info日志吗?

2021/03/18 14:08:25 [INFO] connection pool is initialized successfully
2021/03/18 14:08:25 [INFO] Example finished
2021/03/18 14:08:25 [FATAL] Fail to create a new session from connection pool, username: user, password: password, Authentication fails, Connection not open

你是在运行example吧?从 Example finished 看出整个连接是没有问题的,example最后会把连接释放,然后关闭链接池。

你先试试不要添加自己的代码,就用example中的跑跑看,输出应该如下:

➜  example git:(master) ✗ go run graph_client_example.go
2021/03/18 14:27:15 [INFO] connection pool is initialized successfully
column names: $^.person.name, $^.person.age, like.likeness
row elements: "Bob", 10, 97.2
valueWrapper type: string
Result of ValueWrapper.AsString(): Bob
Print using ValueWrapper.String(): "Bob"
2021/03/18 14:27:21 [INFO] Example finished

我还没有添加自己的代码,现在就是完全跑的example的

hostAddress := nebula.HostAddress{Host: address, Port: port}
  hostList := []nebula.HostAddress{hostAddress}
  // Create configs for connection pool using default values
  testPoolConfig := nebula.GetDefaultConf()

  // Initialize connection pool
  pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, nebulaLog)
  if err != nil {
    nebulaLog.Fatal(fmt.Sprintf("Fail to initialize the connection pool, host: %s, port: %d, %s", address, port, err.Error()))
  }
  // Close all connections in the pool
  defer pool.Close()
  // Create session and send query in go routine
  var wg sync.WaitGroup

  go func(wg *sync.WaitGroup) {
    defer wg.Done()
    // Create session
    session, err := pool.GetSession(username, password)
    if err != nil {
      nebulaLog.Fatal(fmt.Sprintf("Fail to create a new session from connection pool, username: %s, password: %s, %s",
        username, password, err.Error()))
    }
    // Release session and return connection back to connection pool
    defer session.Release()
    // Method used to check execution response
    checkResultSet := func(prefix string, res *nebula.ResultSet) {
      if !res.IsSucceed() {
        fmt.Printf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg())
      }
    }
    {
      createSchema := "CREATE SPACE IF NOT EXISTS test; " +
        "USE test;" +
        "CREATE TAG IF NOT EXISTS person(name string, age int);" +
        "CREATE EDGE IF NOT EXISTS like(likeness double)"

      // Excute a query
      resultSet, err := session.Execute(createSchema)
      if err != nil {
        fmt.Print(err.Error())
        return
      }
      checkResultSet(createSchema, resultSet)
    }
    time.Sleep(5 * time.Second)
    {
      insertVertexes := "INSERT VERTEX person(name, age) VALUES " +
        "'Bob':('Bob', 10), " +
        "'Lily':('Lily', 9), " +
        "'Tom':('Tom', 10), " +
        "'Jerry':('Jerry', 13), " +
        "'John':('John', 11);"

      // Insert multiple vertexes
      resultSet, err := session.Execute(insertVertexes)
      if err != nil {
        fmt.Print(err.Error())
        return
      }
      checkResultSet(insertVertexes, resultSet)
    }

    {
      // Insert multiple edges
      insertEdges := "INSERT EDGE like(likeness) VALUES " +
        "'Bob'->'Lily':(80.0), " +
        "'Bob'->'Tom':(70.0), " +
        "'Lily'->'Jerry':(84.0), " +
        "'Tom'->'Jerry':(68.3), " +
        "'Bob'->'John':(97.2);"

      resultSet, err := session.Execute(insertEdges)
      if err != nil {
        fmt.Print(err.Error())
        return
      }
      checkResultSet(insertEdges, resultSet)
    }

    {
      query := "GO FROM 'Bob' OVER like YIELD $^.person.name, $^.person.age, like.likeness"
      // Send query
      resultSet, err := session.Execute(query)
      if err != nil {
        fmt.Print(err.Error())
        return
      }
      checkResultSet(query, resultSet)

      // Get all column names from the resultSet
      colNames := resultSet.GetColNames()
      fmt.Printf("column names: %s\n", strings.Join(colNames, ", "))

      // Get a row from resultSet
      record, err := resultSet.GetRowValuesByIndex(0)
      if err != nil {
        nebulaLog.Error(err.Error())
      }
      // Print whole row
      fmt.Printf("row elements: %s\n", record.String())
      // Get a value in the row by column index
      valueWrapper, err := record.GetValueByIndex(0)
      if err != nil {
        nebulaLog.Error(err.Error())
      }
      // Get type of the value
      fmt.Printf("valueWrapper type: %s \n", valueWrapper.GetType())
      // Check if valueWrapper is a string type
      if valueWrapper.IsString() {
        // Convert valueWrapper to a string value
        v1Str, err := valueWrapper.AsString()
        if err != nil {
          nebulaLog.Error(err.Error())
        }
        fmt.Printf("Result of ValueWrapper.AsString(): %s\n", v1Str)
      }
      // Print ValueWrapper using String()
      fmt.Printf("Print using ValueWrapper.String(): %s", valueWrapper.String())
    }
  }(&wg)
  wg.Wait()

  fmt.Print("\n")
  nebulaLog.Info("Example finished")

你可以用 connection_pool 的 Ping()接口试一下在链接池创建成功后,能不能Ping通?

// Check avaliability of host
func (pool *ConnectionPool) Ping(host HostAddress, timeout time.Duration) error {
	newConn := newConnection(host)
	// Open connection to host
	if err := newConn.open(newConn.severAddress, timeout); err != nil {
		return err
	}
	newConn.close()
	return nil
}