hybrid.diffs

application/octet-stream

Filename: hybrid.diffs
Type: application/octet-stream
Part: 0
Message: RE: Unexpected behavior when setting "idle_replication_slot_timeout"
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index c09a636ce95..d57ed1dbb1b 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -1713,6 +1713,19 @@ DetermineSlotInvalidationCause(uint32 possible_causes, ReplicationSlot *s,
 
 		if (CanInvalidateIdleSlot(s))
 		{
+			/*
+			 * We simulate the invalidation due to idle_timeout as the minimum
+			 * time idle time is one minute which makes tests take a long
+			 * time.
+			 */
+#ifdef USE_INJECTION_POINTS
+			if (IS_INJECTION_POINT_ATTACHED("slot-timeout-inval"))
+			{
+				*inactive_since = 0;	/* since the beginning of time */
+				return RS_INVAL_IDLE_TIMEOUT;
+			}
+#endif
+
 			/*
 			 * Check if the slot needs to be invalidated due to
 			 * idle_replication_slot_timeout GUC.
diff --git a/src/test/recovery/t/044_invalidate_inactive_slots.pl b/src/test/recovery/t/044_invalidate_inactive_slots.pl
index 4abcc960f19..e20c64ec402 100644
--- a/src/test/recovery/t/044_invalidate_inactive_slots.pl
+++ b/src/test/recovery/t/044_invalidate_inactive_slots.pl
@@ -56,8 +56,24 @@ $node->safe_psql(
 
 my $log_offset = -s $node->logfile;
 
-# Wait a bit for the replication slots to become invalid
-$node->safe_psql('postgres', "SELECT pg_sleep(2)");
+# Check if the 'injection_points' extension is available, as it may be
+# possible that this script is run with installcheck, where the module
+# would not be installed by default.
+if ($node->check_extension('injection_points'))
+{
+	# Register an injection point on the node to forcibly cause a slot
+	# invalidation due to idle_timeout
+	$node->safe_psql('postgres', 'CREATE EXTENSION injection_points;');
+
+	$node->safe_psql('postgres',
+		"SELECT injection_points_attach('slot-timeout-inval', 'error');");
+}
+else
+{
+	# Otherwise wait a bit for the replication slots to become invalid
+	$node->safe_psql('postgres', "SELECT pg_sleep(2)");
+}
+
 # Slot invalidation occurs during a checkpoint, so perform a checkpoint to
 # invalidate the slots.
 $node->safe_psql('postgres', "CHECKPOINT");