I'm using PostgreSQL 8.3, and writing a program in C++ that uses the libpq
API. I execute commands asynchronously with the PQsendQuery()
function. I'm trying to implement a timeout processing feature. I implemented it by calling PQcancel()
when the timeout expires. I tested it with a query that returns 100 000 rows (it lasts about 0.5 s) with a timeout of 1 ms, and found that instead of cancelling the command, PQcancel()
blocks until the server finishes execution, then returns with a successful query.
I understand that the documentation says that even with a successful cancel request the query may still be executed. My problem is that PQcancel()
blocks my thread of execution, which is not acceptable because I use asynchronous processing (using the Boost Asio framework) so my program, which may have other tasks to do other than executing the SQL query, runs only on one thread.
Is it normal that PQcancel()
blocks? Is there any way to make a non-blocking cancel request?