memgraph / documentation

The official documentation for Memgraph open-source graph database.
https://memgraph.com/docs
MIT License
9 stars 10 forks source link

Not able to connect to Memgraph via IPv6 host addres #1010

Open antejavor opened 1 month ago

antejavor commented 1 month ago

Create a IPv6 network:

docker network create --ipv6 --subnet 2001:db8::/64 ip6net

Start Memgraph in IPv6 network:

docker run --name memgraph --network ip6net -p 7687:7687 memgraph/memgraph:2.20.0 --log-level=TRACE --also-log-to-stderr --telemetry-enabled=False

Keep in mind that now Bolt port works both for IPv4 and IPv6 networking.

maple@big-bang:~$ ss -tuln | grep LISTEN
tcp   LISTEN 0      4096                                     0.0.0.0:7687       0.0.0.0:*
tcp   LISTEN 0      128                                    127.0.0.1:631        0.0.0.0:*
tcp   LISTEN 0      4096                               127.0.0.53%lo:53         0.0.0.0:*
tcp   LISTEN 0      128                                      0.0.0.0:22         0.0.0.0:*
tcp   LISTEN 0      1024                                   127.0.0.1:43509      0.0.0.0:*
tcp   LISTEN 0      4096                              100.64.149.141:54544      0.0.0.0:*
tcp   LISTEN 0      4096                                        [::]:7687          [::]:*
tcp   LISTEN 0      4096   [fd7a:115c:a1e0:ab12:4843:cd96:6240:958d]:54544         [::]:*
tcp   LISTEN 0      128                                        [::1]:631           [::]:*
tcp   LISTEN 0      128                                         [::]:22            [::]:*

This can be checked via: docker container inspect memgraph --format "{{json .NetworkSettings.Ports}}"

The problem is that connection to the [::] [::1] or IPv6 address from the container "GlobalIPv6Address": "2001:db8::2", does not work in any way, and results in the following errors, depending how you change the driver or URI config:

maple@big-bang:~/repos/mgconsole/build/src$ ./mgconsole --host=2001:db8::2
Connection failure: couldn't connect to host: Connection refused

Neo4j driver:

Error: Couldn't connect to [::]:7687 (resolved to ('[::]:7687',)):
Failed to read any data from server ResolvedIPv6Address(('::', 7687, 0, 0)) after connected (deadline <neo4j._deadline.Deadline object at 0x70d036001de0>)
maple@big-bang:~/repos/mgconsole/build/src$ ./mgconsole --host=ip6-localhost
mg_raw_transport_recv: Connection reset by peer
Connection failure: failed to receive handshake response

Snippets:

from neo4j import GraphDatabase

URI = "bolt://[::]:7687"
AUTH = ("", "")
employee_threshold=10

def main():
    with GraphDatabase.driver(URI, auth=AUTH) as driver:
        with driver.session(database="") as session:
            for i in range(100):
                try:
                    session.run("CREATE (a:Person {name: 'Alice'})")
                except Exception as e:
                    print(f"Error: {e}")

main()
import mgclient

try:
    conn = mgclient.connect(host='[::]', port=7687)
    cursor = conn.cursor()
    cursor.execute("CREATE (a:Person {name: 'Alice'})")
    cursor.close()
    print("Success")
except Exception as e:
    print(f"Error: {e}")

Context:

maple@big-bang:~$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   big-bang

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
as51340 commented 1 month ago

Hi,

Memgraph must be configured to listen on all ipv6 addresses by setting --bolt-address=::.

To run without explicit docker network, use:

docker run --name memgraph -p 7687:7687 memgraph/memgraph:2.20.0 --log-level=TRACE --also-log-to-stderr --telemetry-enabled=False --bolt-address=::

For the host parameter in mgconsole or uri in Python driver, you can use :: (corresponding to IPv4 0.0.0.0) or ::1 (corresponding to Ipv4 127.0.0.1).

If you create an explicit ipv6 docker network, you can then also use network's ipv6 address to connect in addition to :: and ::1.

antejavor commented 1 month ago

Nice, then this is a documentation issue, will transfer this issue on the docs, so we can properly document this.

Please edit your answer here 🙏 : https://stackoverflow.com/questions/74025244/how-to-connect-using-neo4j-driver-over-ipv6

antejavor commented 3 weeks ago

We also need to document/test similar for monitoring server.