drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.45k stars 1.1k forks source link

After restarting postgres server manually a drogon project quits unexpectedly #1407

Closed BurievSardor closed 5 months ago

BurievSardor commented 1 year ago

If I restart postgres server manually, my drogon project quits and I get the following error: "FATAL Socket fd < 0, Usually this is because the number of files opened by the program exceeds the system limit. Please use the ulimit command to check".

VirtualBox 6.1.38 Ubuntu 20.04.2 LTS QtCreator 5.0.2 GCC11 Drogon version 1.7.5

nqf commented 1 year ago

I have the same problem

lldxflwb commented 1 year ago

我遇到过相同的错误,这是在pg的ip无法连接的情况下,可能是尝试打开了很多次,导致系统打开的文件过多出错

lldxflwb commented 1 year ago

补充一下,遇到这种情况,是在服务启动后20s内(如果IP连不上的话)

an-tao commented 1 year ago

I can't reproduce this issue, please contact me with QQ, @lldxflwb

Demilivor commented 5 months ago

Hello @an-tao Is there any progress on this issue?

The problem may be located in these lines: https://github.com/drogonframework/drogon/blob/96919df488e0ebaa0ed304bbd76bba33508df3cc/orm_lib/src/postgresql_impl/PgBatchConnection.cc#L80-L97

Here we do exit(1). It is possible to reproduce the issue using these steps: 1) Open connection to Postgres using DbClient 2) Stop Postgres database service. 3) Drogon will try to reconnect to the Postgres database after 1 second, but the connection will not be established. and exit(1) will be called

Reconnection to the Postgres database happens here: https://github.com/drogonframework/drogon/blob/96919df488e0ebaa0ed304bbd76bba33508df3cc/orm_lib/src/DbClientImpl.cc#L424-L446

Demilivor commented 5 months ago

This diagram shows the workflow of an application using Drogon code: DbClientDiagram

This scheme shows that application stops working on the database shutdown.


Here is proposed solution scheme with 1 second interval reconnection: DbClientDiagram_fixed

In this case, if Drogon loses connection to the database then framework will try to reconnect to the database with 1 second interval until connection is established. After connection is established, all queued SQL queries will be executed.

an-tao commented 5 months ago

This diagram shows the workflow of an application using Drogon code: DbClientDiagram

This scheme shows that application stops working on the database shutdown.

Here is proposed solution scheme with 1 second interval reconnection: DbClientDiagram_fixed

In this case, if Drogon loses connection to the database then framework will try to reconnect to the database with 1 second interval until connection is established. After connection is established, all queued SQL queries will be executed.

Thank you very much for your detailed feedback, I'll take some time to figure it out.