英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论