drogonframework / drogon

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

Implemented database reconnection loop #2003

Closed Demilivor closed 2 months ago

Demilivor commented 2 months ago

closes #1407

This PR adds automatic reconnection to the Postgres/MySQL database with 1-second interval if connection was not established instead of exit(1)

Demilivor commented 2 months ago

Hello @an-tao

Could you please review this PR. Please feel free to suggest improvements.

hwc0919 commented 2 months ago

Thanks for the PR! Could you put the init() methods right after the constructor? That really helps the code review. The diff viewer now displays in a stupid way...

Demilivor commented 2 months ago

Thanks for the PR! Could you put the init() methods right after the constructor? That really helps the code review. The diff viewer now displays in a stupid way...

Done!

Demilivor commented 2 months ago

My latest update failed test:

In test case PgPipelineTest
/home/admin/arenadata_drogon/drogon/orm_lib/tests/pipeline_test.cpp:37  FAILED:
  Reason: PgPipelineTest_init(0) what():SQL execution timeout

I just reproduced the issue on my personal PC. I'm going to investigate this failure on Monday.

hwc0919 commented 2 months ago

closes #1407

This PR adds automatic reconnection to the Postgres/MySQL database with 1-second interval if connection was not established instead of exit(1)

To be noted, auto-reconnect is already supported. This exit(-1) happens on some edge cases, such as reaching open socket limits.

rvasin commented 2 months ago

To be noted, auto-reconnect is already supported. This exit(-1) happens on some edge cases, such as reaching open socket limits.

From wiki

The connections managed by DbClient are always reconnected, so users don't need to care about the connection status. They are almost always connected.

The problem is not with "some edge cases" because simple drop of connection to PostgreSQL for few seconds makes the whole Drogon's application exit(-1).

Demilivor commented 2 months ago

The issue with PgPipelineTest should be fixed now.

Demilivor commented 2 months ago

One more update: 1) Added connection initialization to make db_listener_test test pass.

I'm not familiar with the internal Drogon tests. Do you have a guide how I can prepare the test environment on my PC and run all Drogon tests before updating PR?

an-tao commented 2 months ago

One more update:

  1. Added connection initialization to make db_listener_test test pass.

I'm not familiar with the internal Drogon tests. Do you have a guide how I can prepare the test environment on my PC and run all Drogon tests before updating PR?

You could refer to the github actions configuration: https://github.com/drogonframework/drogon/tree/master/.github/workflows