drogon icon indicating copy to clipboard operation
drogon copied to clipboard

PgConnection does not reconnect to PostgreSQL after PostgreSQL server was restarted

Open Demilivor opened this issue 7 months ago • 1 comments

Describe the bug Non-batch PgConnection does not reconnect to Postgres after connection was lost. Thread sanitizer finds different data races during the application work.

I was not able to reproduce the problem with PgConnection with batch support (PgBatchConnection.cc)

To Reproduce Steps to reproduce the behavior:

  1. Checkout test files: https://github.com/Demilivor/DrogonDoesNotReconnect
  2. Install Postgres client library without batching support
  3. Install clang-18 or later (test expects that clang and clang++ aliases refer to clang 18+ version)
  4. Install docker compose and cmake
  5. Run ./test.sh in the folder with test files

Expected behavior Test always passed, and thread sanitizer finds no data races.

Desktop (please complete the following information):

  • Ubuntu 22.04.4 LTS

Additional context

How does the test work

  1. test.sh launches docker compose file with PostgreSQL
  2. test.sh builds and launched the code from main.cpp with Thread Sanitizer in a separate child process.
  3. test.sh starts and stops Postgres and sleeps between operations.
  4. Main.cpp creates multiple DB clients; one thread uses one client. Each client runs queries in transactions and sleeps some time between SQL statements. After the SIGINT/SIGTERM is received, the test expects that the Postgres connection will be restored and next transaction will execute without errors. If any connection will not be restored after postgres stop restarting, the error counter is increased. The program returns 0 in case of no errors. Other error code in case of fails.
  5. test.sh after multiple Postgres restarts with started Postgres sleep 30 seconds to give drogon time to reconnect and send SIGTERM
  6. test.sh stops docker compose and returns the error code from compiled code with main.cpp

Data races

Thread sanitizer finds these races: https://github.com/Demilivor/DrogonDoesNotReconnect/blob/main/data_races.md

Demilivor avatar May 20 '25 12:05 Demilivor

Same problem.

oleglpts avatar Jun 25 '25 17:06 oleglpts