Skip to content

Commit

Permalink
Fix assertion failure in cursor_fetcher_rewind
Browse files Browse the repository at this point in the history
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
  • Loading branch information
svenklemm committed Dec 13, 2021
1 parent babcc8e commit 1b4780d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tsl/src/remote/cursor_fetcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ cursor_fetcher_rewind(DataFetcher *df)
{
char sql[64];

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

if (!cursor->state.eof)
async_request_discard_response(cursor->state.data_req);
Expand Down
28 changes: 28 additions & 0 deletions tsl/test/shared/expected/dist_fetcher_type.out
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,31 @@ limit 1;
(1 row)

reset timescaledb.remote_data_fetcher;
-- #3786 test for assertion failure in cursor_fetcher_rewind
SET jit TO off;
SELECT *
FROM devices AS d
WHERE
EXISTS(
SELECT 1
FROM metrics_dist AS m,
LATERAL(
SELECT 1
FROM insert_test it
WHERE
EXISTS(
SELECT 1
FROM dist_chunk_copy AS ref_2
WHERE
it.id IS NOT NULL AND
EXISTS(SELECT d.name AS c0 FROM metrics_int WHERE NULL::TIMESTAMP <= m.time)
)
) AS l
WHERE d.name ~~ d.name
)
ORDER BY 1,2;
device_id | name
-----------+------
(0 rows)

RESET jit;
25 changes: 25 additions & 0 deletions tsl/test/shared/sql/dist_fetcher_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,28 @@ where t1.id = t2.id + 1
limit 1;

reset timescaledb.remote_data_fetcher;

-- #3786 test for assertion failure in cursor_fetcher_rewind
SET jit TO off;
SELECT *
FROM devices AS d
WHERE
EXISTS(
SELECT 1
FROM metrics_dist AS m,
LATERAL(
SELECT 1
FROM insert_test it
WHERE
EXISTS(
SELECT 1
FROM dist_chunk_copy AS ref_2
WHERE
it.id IS NOT NULL AND
EXISTS(SELECT d.name AS c0 FROM metrics_int WHERE NULL::TIMESTAMP <= m.time)
)
) AS l
WHERE d.name ~~ d.name
)
ORDER BY 1,2;
RESET jit;

0 comments on commit 1b4780d

Please sign in to comment.