reworkd / AgentGPT

🤖 Assemble, configure, and deploy autonomous AI Agents in your browser.
https://agentgpt.reworkd.ai
GNU General Public License v3.0
31.83k stars 9.25k forks source link

[Bug] Should we use some url instead "db" for database host address? #762

Open yhyu13 opened 1 year ago

yhyu13 commented 1 year ago

Please check that this issue hasn't been reported before.

Expected Behavior

It may affect other users, in my case I could not start agentgpt at v0.7 beta release due to the database host address issues I found.

Note, I am running with docker in host network mode, so every database host points to 127.0.0.1 in my setup. I am not sure if the bug only happen to me because of host network mode setup or not.

Current behaviour

In three places I found "db" is misused:

1, docker-compose.yml :

REWORKD_PLATFORM_DB_HOST: db

2, .env.example :

REWORKD_PLATFORM_DATABASE_HOST="db"
.
.
.
DATABASE_HOST="db"

3, , use variable db which not defined, and hardcoded database port

next/entrypoint.sh,

./wait-for-db.sh db 3307

platform/entrypoint.sh, OMG the port is not correct, and we should make platform waiting for database in principle

host=db
port=3306

Steps to reproduce

just run docker compose w/o -d (detachment)

docker-compose -f ./local-docker-compose.yml up --remove-orphans --build

And see the output, it shows next and platform is stuck waiting for database, because "db" is not defined to a valid URL

next    | Database is available! Continuing...
platform    | Database is available! Continuing...

Not only that, if you skip the waiting for server and enter localhost:3000, you cannot login because the server cannot reach "db" (it is expected to be a URL, not "db")

platform    |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 898, in __connect
platform    |     self.dbapi_connection = connection = pool._invoke_creator(self)
platform    |     │    │                               │    │               └ <sqlalchemy.pool.base._ConnectionRecord object at 0x7fbef9c75710>
platform    |     │    │                               │    └ <function create_engine.<locals>.connect at 0x7fbefca54720>
platform    |     │    │                               └ <sqlalchemy.pool.impl.AsyncAdaptedQueuePool object at 0x7fbefc8c7e90>
platform    |     │    └ <member 'dbapi_connection' of '_ConnectionRecord' objects>
platform    |     â”” <sqlalchemy.pool.base._ConnectionRecord object at 0x7fbef9c75710>
platform    |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 637, in connect
platform    |     return dialect.connect(*cargs, **cparams)
platform    |            │       │        │        └ {'host': 'db', 'db': 'reworkd_platform', 'user': 'reworkd_platform', 'password': 'reworkd_platform', 'port': 3307, 'client_fl...
platform    |            │       │        └ []
platform    |            │       └ <function DefaultDialect.connect at 0x7fbf7be25440>
platform    |            â”” <sqlalchemy.dialects.mysql.aiomysql.MySQLDialect_aiomysql object at 0x7fbf01bd6b50>
platform    |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 616, in connect
platform    |     return self.loaded_dbapi.connect(*cargs, **cparams)
platform    |            │    │            │        │        └ {'host': 'db', 'db': 'reworkd_platform', 'user': 'reworkd_platform', 'password': 'reworkd_platform', 'port': 3307, 'client_fl...
platform    |            │    │            │        └ ()
platform    |            │    │            └ <function AsyncAdapt_aiomysql_dbapi.connect at 0x7fbefca6bd80>
platform    |            │    └ <sqlalchemy.dialects.mysql.aiomysql.AsyncAdapt_aiomysql_dbapi object at 0x7fbefcb72e50>
platform    |            â”” <sqlalchemy.dialects.mysql.aiomysql.MySQLDialect_aiomysql object at 0x7fbf01bd6b50>
platform    |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/aiomysql.py", line 267, in connect
platform    |     await_only(self.aiomysql.connect(*arg, **kw)),
platform    |     │          │    │        │        │      └ {'host': 'db', 'db': 'reworkd_platform', 'user': 'reworkd_platform', 'password': 'reworkd_platform', 'port': 3307, 'client_fl...
platform    |     │          │    │        │        └ ()
platform    |     │          │    │        └ <function connect at 0x7fbefc8f76a0>
platform    |     │          │    └ <module 'aiomysql' from '/usr/local/lib/python3.11/site-packages/aiomysql/__init__.py'>
platform    |     │          └ <sqlalchemy.dialects.mysql.aiomysql.AsyncAdapt_aiomysql_dbapi object at 0x7fbefcb72e50>
platform    |     â”” <function await_only at 0x7fbf7c64fc40>
platform    |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 126, in await_only
platform    |     return current.driver.switch(awaitable)  # type: ignore[no-any-return]
platform    |            │                     └ <aiomysql.utils._ConnectionContextManager object at 0x7fbef9c735c0>
platform    |            â”” <_AsyncIoGreenlet object at 0x7fbef9c7d800 (otid=0x7fbf7d46f7e0) dead>
platform    |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 187, in greenlet_spawn
platform    |     value = await result
platform    |                   â”” <aiomysql.utils._ConnectionContextManager object at 0x7fbef9c735c0>
platform    |   File "/usr/local/lib/python3.11/site-packages/aiomysql/connection.py", line 75, in _connect
platform    |     await conn._connect()
platform    |           │    └ <function Connection._connect at 0x7fbefc7b49a0>
platform    |           â”” <aiomysql.connection.Connection object at 0x7fbef9c7c050>
platform    |   File "/usr/local/lib/python3.11/site-packages/aiomysql/connection.py", line 558, in _connect
platform    |     raise OperationalError(2003,
platform    |           â”” <class 'pymysql.err.OperationalError'>
platform    | 
platform    | sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'db'")
platform    | (Background on this error at: https://sqlalche.me/e/20/e3q8)

Possible solution

I've proposed several changes regard to the three places mentioned previously:

https://github.com/yhyu13/AgentGPT/commit/9d2b2bd96bc0ff941f1fb1b289549a91012585ee

env.example image

https://github.com/yhyu13/AgentGPT/commit/03be1c3b2f19df83b0bab4ab3920d7be71b618cd

docker-compose.yml image

next/entrypoint.sh image

platform/entrypoint.sh image

Which Operating Systems are you using?

Acknowledgements

yhyu13 commented 1 year ago

Let me know if your idea. Is it a bug or is it a feature that I did not setup correctly in my workspace?

jasangill1 commented 1 year ago

Hello @yhyu13 could you retry the setup script? we have made some changes that may resolve this issue!

yhyu13 commented 1 year ago

Hello @yhyu13 could you retry the setup script? we have made some changes that may resolve this issue!

@jasangill1 Sure, I will try it with latest AgentGPT version

jasangill1 commented 1 year ago

@yhyu13 whereabouts are you located? and have you had any luck!!

darkanubis0100 commented 1 year ago

Fixed in my PR https://github.com/reworkd/AgentGPT/pull/1335

yhyu13 commented 11 months ago

@darkanubis0100 While your pr on custom network group reamains open,

here is my solution again for v1.0.0 local deployment. Added local startup scripts and made chage to "agent_db" (how does that even work? I don't believe "agent_db" could translate to 127.0.0.1 or 0.0.0.0 automatically just like localhost)

https://github.com/yhyu13/AgentGPT/commit/09e1e0447b1a5619e3a333668c1bb251d1007db3

PS: Local AgentGPT works best on mozzilla (Edge sometimes rants "Network Error" which equals to not be able to connect to 8000 python backend, hope to save your hours of wasted debugging time)

darkanubis0100 commented 11 months ago

@darkanubis0100 While your pr on custom network group reamains open,

here is my solution again for v1.0.0 local deployment. Added local startup scripts and made chage to "agent_db" (how does that even work? I don't believe "agent_db" could translate to 127.0.0.1 or 0.0.0.0 automatically just like localhost)

yhyu13@09e1e04

PS: Local AgentGPT works best on mozzilla (Edge sometimes rants "Network Error" which equals to not be able to connect to 8000 python backend, hope to save your hours of wasted debugging time)

Unfortunately that's not functional when you use Windows and Edge, my solution worked on any system and with any browser, which is why I still have the PR