drogon
drogon copied to clipboard
PgConnection does not reconnect to PostgreSQL after PostgreSQL server was restarted
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:
- Checkout test files: https://github.com/Demilivor/DrogonDoesNotReconnect
- Install Postgres client library without batching support
- Install clang-18 or later (test expects that
clangandclang++aliases refer to clang 18+ version) - Install docker compose and cmake
- Run
./test.shin 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
test.shlaunches docker compose file with PostgreSQLtest.shbuilds and launched the code frommain.cppwith Thread Sanitizer in a separate child process.test.shstarts and stops Postgres and sleeps between operations.- 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.
test.shafter multiple Postgres restarts with started Postgres sleep 30 seconds to give drogon time to reconnect and send SIGTERMtest.shstops 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
Same problem.