连接超时:如果Cypher包含任何路径但没有RETURN,则查询会卡住。

huangapple go评论51阅读模式
英文:

Timeout while reading from connection: Query gets stuck if Cypher contains any path and does not have RETURN

问题

我在Windows 11上使用WSL2运行Memgraph 2.4.1我的`memgraph+neo4j-go-driver`在包含路径但没有`RETURN`的情况下会卡在`sess.Close``res.Consume`

这是我的代码

    package main
    
    import (
    	"context"
    	"fmt"
    	"time"
    
    	"github.com/neo4j/neo4j-go-driver/v5/neo4j"
    )
    
    const url = "bolt://localhost:7687"
    
    func query(driver neo4j.DriverWithContext, cypher string) error {
    	ctx := context.Background()
    	ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
    	defer cancel()
    	sess := driver.NewSession(ctx, neo4j.SessionConfig{})
    	defer sess.Close(ctx) // 如果没有res.Consume,这里会卡住
    
    	res, err := sess.Run(ctx, cypher, nil)
    	if err != nil {
    		return err
    	}
    
    	for res.Next(ctx) {
    		fmt.Println(res.Record().Values...)
    	}
    
    	err = res.Err()
    	if err != nil {
    		return err
    	}
    
    	if res.IsOpen() {
    		fmt.Println("尝试消耗")
    		_, err := res.Consume(ctx)
    		if err != nil {
    			return err
    		}
    		fmt.Println("好的")
    	}
    
    	return nil
    }
    
    func example() error {
    	driver, err := neo4j.NewDriverWithContext(url, neo4j.BasicAuth("", "", ""))
    	if err != nil {
    		return err
    	}
    
    	if err := query(driver, "RETURN 1+1"); err != nil {
    		return err
    	}
    	if err := query(driver, "MATCH ()-[r]->() SET r.test = 123 RETURN DISTINCT 1"); err != nil {
    		fmt.Println(err)
    	}
    	if err := query(driver, "MATCH ()-[r]->() SET r.test = 123"); err != nil {
    		fmt.Println(err)
    	}
    	if err := query(driver, "MATCH (r)-[]->() SET r.test = 123"); err != nil {
    		fmt.Println(err)
    	}
    
    	return nil
    }
    
    func main() {
    	if err := example(); err != nil {
    		panic(err)
    	}
    }
英文:

I have Memgraph 2.4.1 running using WSL2 on Windows 11. My memgraph+neo4j-go-driver is stuck on sess.Close or res.Consume if cypher contains any path and does not have RETURN.

This is my code:

package main
import (
"context"
"fmt"
"time"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
)
const url = "bolt://localhost:7687"
func query(driver neo4j.DriverWithContext, cypher string) error {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
sess := driver.NewSession(ctx, neo4j.SessionConfig{})
defer sess.Close(ctx) // stuck here is no res.Consume
res, err := sess.Run(ctx, cypher, nil)
if err != nil {
return err
}
for res.Next(ctx) {
fmt.Println(res.Record().Values...)
}
err = res.Err()
if err != nil {
return err
}
if res.IsOpen() {
fmt.Println("trying to consume")
_, err := res.Consume(ctx)
if err != nil {
return err
}
fmt.Println("ok")
}
return nil
}
func example() error {
driver, err := neo4j.NewDriverWithContext(url, neo4j.BasicAuth("", "", ""))
if err != nil {
return err
}
if err := query(driver, "RETURN 1+1"); err != nil {
return err
}
if err := query(driver, "MATCH ()-[r]->() SET r.test = 123 RETURN DISTINCT 1"); err != nil {
fmt.Println(err)
}
if err := query(driver, "MATCH ()-[r]->() SET r.test = 123"); err != nil {
fmt.Println(err)
}
if err := query(driver, "MATCH (r)-[]->() SET r.test = 123"); err != nil {
fmt.Println(err)
}
return nil
}
func main() {
if err := example(); err != nil {
panic(err)
}
}

答案1

得分: 0

这是 Memgraph 版本 2.4.1 中的一个错误。您需要使用 Memgraph 2.5.2 或更新版本。

英文:

This was a bug in Memgraph version 2.4.1. You need to use Memgraph 2.5.2 or newer.

huangapple
  • 本文由 发表于 2023年7月4日 22:40:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613737.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定