| From: | jiye <jiye_sw(at)126(dot)com> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | FDW connection drops with "Connection timed out" during async append query due to TCP receive buffer filling up |
| Date: | 2026-03-10 10:17:44 |
| Message-ID: | 10df46d9.7dc2.19cd740a640.Coremail.jiye_sw@126.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hello:
I encountered an issue with foreign table asynchronous scans.
I'm testing on PostgreSQL 17 in a Windows WSL environment, with TCP keepalive settings configured as follows:
configure:
tcp_keepalives_idle = 2
tcp_keepalives_interval = 2
tcp_keepalives_count = 3
tcp_user_timeout = 9
The foreign table was created with:
sql:
CREATE TABLE ftab (a int, data varchar);
I inserted test data using:
sql:
INSERT INTO ftab
SELECT generate_series(1, 10000),
substring(md5(random()::text) || repeat(md5(random()::text), 127), 1, 40960);
Then I executed an async append query that unions with a simple query:
sql:
SELECT f1(), 'local-data'
UNION ALL
SELECT * FROM f_ftab
LIMIT 2;
Note: f1() is a function that sleeps for 10 seconds, created by:
sql
CREATE OR REPLACE FUNCTION f1()
RETURNS integer
LANGUAGE plpgsql AS $$
BEGIN
PERFORM pg_sleep(10);
RETURN 1;
END; $$;
The abnormal behavior was reproduced: the foreign data server connection was disconnected, with the following error logs:
text
2026-03-10 17:52:55.969 CST [820] LOG: statement: FETCH 100 FROM c1
2026-03-10 17:52:56.495 CST [820] LOG: could not receive data from client: Connection timed out
2026-03-10 17:52:56.495 CST [820] LOG: unexpected EOF on client connection with an open transaction
The async foreign table query failed with the error:
text
ERROR: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
invalid socket
CONTEXT: remote SQL command: SELECT a, data FROM public.ftab
WARNING: no connection to the server
This is a minimal working example. In practice, if the local table scan takes too long and the foreign table has sufficiently wide rows, this issue may reproduce.
In my understanding, when performing a local sequential scan, the PostgreSQL backend fetches data from the local plan without fetching any data from the FDW. As a result, the TCP receive buffer may become full, causing the FDW connection to be disconnected.
I believe this is a minor issue. How can I resolve this problem?
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Laurenz Albe | 2026-03-10 17:16:04 | Re: FDW connection drops with "Connection timed out" during async append query due to TCP receive buffer filling up |
| Previous Message | Michael Paquier | 2026-03-09 22:10:13 | Re: BUG #18943: Return value of a function 'xmlBufferCreate' isdereferenced at xpath.c:177 without checking for NUL |