Client connection error : UNKNOWN:failed to connect to all addresses: ipv4:127.0.0.1:9080: Failed to connect to remote host: Connection refused
Report a Dgraph Client Bug
What Dgraph client (and version) are you using?
(put “x” in the box to select)
- Dgo
- PyDgraph
- Dgraph4J
- Dgraph-js
- Dgraph-js-http
- Dgraph.NET
Version:
Pydgraph==21.3.2
What version of Dgraph are you using?
Latest docker image
Have you tried reproducing the issue with the latest release?
Yes
What is the hardware spec (RAM, OS)?
Apple M1 (Mac OS Monterey)
Apple Intel (Mac OS Catalina)
Steps to reproduce the issue (command/config used to run Dgraph).
- Run the docker-compose to bring up FastAPI and Dgraph(alpha, zero)
- Try to create connection client using pydgraph
We’re using docker-compose to spin up FastAPI with Dgraph DB and running into connection issues when creating the client. We also tried to whitelist all IPs for alpha instance.
Docker-compose file
version: '3.8'
services:
web:
build: .
command: uvicorn webapp.app.main:app --host 0.0.0.0
depends_on:
- zero
- alpha
volumes:
- .:/app
ports:
- 8000:8000
zero:
image: dgraph/dgraph:latest
container_name: dgraph-zero
volumes:
- dgraph:/dgraph
ports:
- 5080:5080
- 6080:6080
restart: on-failure
command: dgraph zero --my=zero:5080
alpha:
image: dgraph/dgraph:latest
container_name: dgraph-alpha
volumes:
- dgraph:/dgraph
ports:
- 8080:8080
- 9080:9080
restart: on-failure
command: dgraph alpha --my=alpha:7080 --security "whitelist=0.0.0.0/0" --zero=zero:5080
volumes:
dgraph:
Expected behaviour and actual result.
We should be able to create a connection client which can be used to run mutations/queries
But instead we get the following error
This is the error trace
dgraph-assessment-poc-web-1 | File "/webapp/app/./webapp/app/main.py", line 60, in query1_func
dgraph-assessment-poc-web-1 | result = dgraph_object.client.txn(read_only=True).query(query, variables=variables)
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/pydgraph/txn.py", line 62, in query
dgraph-assessment-poc-web-1 | return self.do_request(req, timeout=timeout, metadata=metadata, credentials=credentials)
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/pydgraph/txn.py", line 126, in do_request
dgraph-assessment-poc-web-1 | self._common_except_mutate(query_error)
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/pydgraph/txn.py", line 229, in _common_except_mutate
dgraph-assessment-poc-web-1 | raise error
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/pydgraph/txn.py", line 102, in do_request
dgraph-assessment-poc-web-1 | response = self._dc.query(request, timeout=timeout,
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/pydgraph/client_stub.py", line 60, in query
dgraph-assessment-poc-web-1 | return self.stub.Query(req, timeout=timeout, metadata=metadata,
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/grpc/_channel.py", line 946, in __call__
dgraph-assessment-poc-web-1 | return _end_unary_response_blocking(state, call, False, None)
dgraph-assessment-poc-web-1 | File "/usr/local/lib/python3.9/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
dgraph-assessment-poc-web-1 | raise _InactiveRpcError(state)
dgraph-assessment-poc-web-1 | grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
dgraph-assessment-poc-web-1 | status = StatusCode.UNAVAILABLE
dgraph-assessment-poc-web-1 | details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:9080: Failed to connect to remote host: Connection refused"
dgraph-assessment-poc-web-1 | **debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:9080: Failed to connect to remote host: Connection refused {created_time:"2023-01-10T21:16:37.786622068+00:00", grpc_status:14}**"
What works
We’d like to also note that we can create client connection sucessfully if we run the standalone cluster using following command
docker run --rm -it -p "8080:8080" -p "9080:9080" -v ~/dgraph:/dgraph "dgraph/standalone:v22.0.2"
and then spinning up FastAPI using
uvicorn webapp.app.main:app --reload --host 0.0.0.0 --port 8000
Let us know if you’d like any other information from our end to fix our docker-compose configuration file. Thank you.