Skip to content

Commit 1b4780d

Browse files
committed
Fix assertion failure in cursor_fetcher_rewind
The code in cursor_fetcher_rewind asserted that there always is an associated request which is not true if EOF was reached already. Found by sqlsmith. Fixes #3786
1 parent babcc8e commit 1b4780d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

tsl/src/remote/cursor_fetcher.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ cursor_fetcher_rewind(DataFetcher *df)
421421
{
422422
char sql[64];
423423

424-
Assert(cursor->state.data_req != NULL);
424+
Assert(cursor->state.eof || cursor->state.data_req != NULL);
425425

426426
if (!cursor->state.eof)
427427
async_request_discard_response(cursor->state.data_req);

tsl/test/shared/expected/dist_fetcher_type.out

+28
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,31 @@ limit 1;
9191
(1 row)
9292

9393
reset timescaledb.remote_data_fetcher;
94+
-- #3786 test for assertion failure in cursor_fetcher_rewind
95+
SET jit TO off;
96+
SELECT *
97+
FROM devices AS d
98+
WHERE
99+
EXISTS(
100+
SELECT 1
101+
FROM metrics_dist AS m,
102+
LATERAL(
103+
SELECT 1
104+
FROM insert_test it
105+
WHERE
106+
EXISTS(
107+
SELECT 1
108+
FROM dist_chunk_copy AS ref_2
109+
WHERE
110+
it.id IS NOT NULL AND
111+
EXISTS(SELECT d.name AS c0 FROM metrics_int WHERE NULL::TIMESTAMP <= m.time)
112+
)
113+
) AS l
114+
WHERE d.name ~~ d.name
115+
)
116+
ORDER BY 1,2;
117+
device_id | name
118+
-----------+------
119+
(0 rows)
120+
121+
RESET jit;

tsl/test/shared/sql/dist_fetcher_type.sql

+25
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,28 @@ where t1.id = t2.id + 1
3737
limit 1;
3838

3939
reset timescaledb.remote_data_fetcher;
40+
41+
-- #3786 test for assertion failure in cursor_fetcher_rewind
42+
SET jit TO off;
43+
SELECT *
44+
FROM devices AS d
45+
WHERE
46+
EXISTS(
47+
SELECT 1
48+
FROM metrics_dist AS m,
49+
LATERAL(
50+
SELECT 1
51+
FROM insert_test it
52+
WHERE
53+
EXISTS(
54+
SELECT 1
55+
FROM dist_chunk_copy AS ref_2
56+
WHERE
57+
it.id IS NOT NULL AND
58+
EXISTS(SELECT d.name AS c0 FROM metrics_int WHERE NULL::TIMESTAMP <= m.time)
59+
)
60+
) AS l
61+
WHERE d.name ~~ d.name
62+
)
63+
ORDER BY 1,2;
64+
RESET jit;

0 commit comments

Comments
 (0)