[#1011350] Infinite loop on statement_timeout connecting to a DB

View Trackers | Bugs | Download .csv | Monitor

Date:
2013-08-05 17:40
Priority:
3
State:
Open
Submitted by:
Fazal Majid (majid)
Assigned to:
Nobody (None)
Category:
None
Group:
None
Resolution:
None
 
Summary:
Infinite loop on statement_timeout connecting to a DB

Detailed description
When a statement_timeout kicks in for a transaction making a call to a PL/Proxy function because PL/Proxy can't open a connection to the remote DB quickly enough, PL/Proxy is caught in an infinite loop that won't stop until the backend is cancelled using pg_cancel_backend() or SIGINT.

The error is different in 2.4 vs. 2.5, but the result is the same.

Here is a test scenario to reproduce the problem:

CREATE EXTENSION plproxy;
CREATE SCHEMA plproxy;

CREATE OR REPLACE FUNCTION plproxy.get_cluster_config(
cluster_name TEXT,
OUT key TEXT,
OUT val TEXT
) RETURNS SETOF RECORD AS $$
BEGIN
key := 'connection_lifetime'::text;
val := text(30*60);
RETURN NEXT;
key := 'query_timeout'::text;
val := '60'; -- 60 seconds to return or bust
RETURN NEXT;
RETURN;
END;
$$ LANGUAGE PLpgSQL;

CREATE OR REPLACE FUNCTION plproxy.get_cluster_version(
i_cluster TEXT
) RETURNS INTEGER AS $$
SELECT 42;
$$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION plproxy.get_cluster_partitions(
cluster_name TEXT
) RETURNS SETOF TEXT AS $$
SELECT
'host=example.com port=5432 dbname=somedb user=sopo password=sopo'::TEXT;
$$ LANGUAGE SQL SECURITY DEFINER;

CREATE OR REPLACE FUNCTION bogus(
sop INTEGER,
OUT foo INTEGER,
OUT bar INTEGER
) RETURNS SETOF RECORD AS $$
CLUSTER 'example';
RUN ON ANY;
$$ LANGUAGE plproxy;

\echo this query should fail with a statement timeout, not hang
SET statement_timeout = 2000;
SELECT bogus(42);

I am attaching a patch against 2.5 I used to fix this on our production systems.

Followup

Message
Date: 2013-11-06 08:58
Sender: Marko Kreen

Dev repo is at https://github.com/markokr/plproxy-dev

But now I pushed current tree to git.pg.org too
Date: 2013-11-06 00:27
Sender: Fazal Majid

I tried checking out git://git.postgresql.org/git/plproxy.git and the last commit in the log is from November 2012. What Git repository should I be looking at?
Date: 2013-11-05 22:42
Sender: Marko Kreen

I fixed the hang differently, but I applied a part of your patch
for unnecessary warning in remote_wait_for_cancel().

Please test current GIT if you have moment.

Attached Files:

Attachments:
plproxy.patch.txt

Changes:

Field Old Value Date By
File Added809: plproxy.patch.txt2013-08-05 17:40majid
Powered By FusionForge