Search code examples
memgraphdb

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


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)
    }
}

Solution

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