Skip to content

Conversation

@mason-sharp
Copy link
Member

Since we reverted cbc5bb1, fix another way and add a test.

@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch task/v5_progress

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mason-sharp mason-sharp marked this pull request as draft February 8, 2026 07:10
Since we reverted cbc5bb1, fix another way and add a test.
@mason-sharp mason-sharp added the in draft This PR created to test domething label Feb 8, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/spock_sync.c (1)

446-458: ⚠️ Potential issue | 🟠 Major

Memory leak: PQescapeLiteral allocations are not freed.

PQescapeLiteral allocates memory via malloc that must be freed with PQfreemem(). In this loop, 5 escaped strings are created per iteration but never freed, causing a memory leak proportional to the number of progress rows processed.

🔧 Proposed fix to free escaped literals
 			char   *updated_by_decode = PQgetvalue(originRes, rno, 6);
+			char   *esc_commit_ts, *esc_lsn, *esc_insert_lsn;
+			char   *esc_updated_ts, *esc_updated_by;
 
 			resetStringInfo(&query);
+			esc_commit_ts = PQescapeLiteral(target_conn, remote_commit_ts,
+							strlen(remote_commit_ts));
+			esc_lsn = PQescapeLiteral(target_conn, remote_lsn,
+							strlen(remote_lsn));
+			esc_insert_lsn = PQescapeLiteral(target_conn, remote_insert_lsn,
+							strlen(remote_insert_lsn));
+			esc_updated_ts = PQescapeLiteral(target_conn, last_updated_ts,
+							strlen(last_updated_ts));
+			esc_updated_by = PQescapeLiteral(target_conn, updated_by_decode,
+							strnlen(updated_by_decode, 64));
+
 			appendStringInfo(&query, upsertQuery,
 							 MySubscription->target->id,
 							 remote_node_id,
-							 PQescapeLiteral(target_conn, remote_commit_ts,
-											 strlen(remote_commit_ts)),
-							 PQescapeLiteral(target_conn, remote_lsn,
-											 strlen(remote_lsn)),
-							 PQescapeLiteral(target_conn, remote_insert_lsn,
-											 strlen(remote_insert_lsn)),
-							 PQescapeLiteral(target_conn, last_updated_ts,
-											 strlen(last_updated_ts)),
-							 PQescapeLiteral(target_conn, updated_by_decode,
-											 strnlen(updated_by_decode, 64)));
+							 esc_commit_ts, esc_lsn, esc_insert_lsn,
+							 esc_updated_ts, esc_updated_by);
 			updateRes = PQexec(target_conn, query.data);
+
+			PQfreemem(esc_commit_ts);
+			PQfreemem(esc_lsn);
+			PQfreemem(esc_insert_lsn);
+			PQfreemem(esc_updated_ts);
+			PQfreemem(esc_updated_by);
🧹 Nitpick comments (2)
src/spock_sync.c (1)

457-458: Consider defining the 64 limit as a named constant.

The magic number 64 for the updated_by_decode length limit should ideally match the actual column size constraint in the spock.progress table. Consider extracting this to a named constant for clarity and to ensure consistency if the schema changes.

+#define UPDATED_BY_DECODE_MAXLEN 64
+
 ...
-							 strnlen(updated_by_decode, 64)));
+							 strnlen(updated_by_decode, UPDATED_BY_DECODE_MAXLEN)));
tests/regress/sql/progress_tracking.sql (1)

143-156: Polling loops may cause flaky tests on slow CI environments.

The fixed iteration counts (100 iterations × 0.1s = 10s max) might not be sufficient on heavily loaded CI runners. Consider increasing the iteration count or adding a diagnostic message when the loop exhausts without finding the expected state.

💡 Suggestion to add timeout diagnostic
 DO $$
 BEGIN
     FOR i IN 1..100 LOOP
         IF EXISTS (
             SELECT 1 FROM spock.local_sync_status
             WHERE sync_relname = 'resync_target_tbl'
               AND sync_status IN ('y', 'r')
         ) THEN
             RETURN;
         END IF;
         PERFORM pg_sleep(0.1);
     END LOOP;
+    RAISE WARNING 'Timed out waiting for resync_target_tbl sync status';
 END;
 $$;

@mason-sharp mason-sharp requested a review from rasifr February 8, 2026 18:56
@rasifr rasifr marked this pull request as ready for review February 9, 2026 12:42
@rasifr rasifr merged commit 96a81ed into v5_STABLE Feb 9, 2026
6 checks passed
@rasifr rasifr deleted the task/v5_progress branch February 9, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in draft This PR created to test domething

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants