Skip to content

Add transient-based mutex lock to prevent concurrent import cron execution #1197

@ineagu

Description

@ineagu

Problem

WordPress pseudo-cron can fire the same scheduled event multiple times if page loads overlap. Without a lock, the same import job can run concurrently, causing duplicate posts (TOCTOU race condition in duplicate detection) and wasted server resources.

Solution

import.php — In run_cron(), add a per-job transient lock:

  • Before each job: check get_transient('feedzy_import_lock_' . $job->ID), skip if active
  • Set transient with 10-minute TTL before running the job
  • Use finally { delete_transient($lock_key); } to ensure cleanup on both success and error
  • Log skipped jobs for debugging

Files Affected

  • includes/admin/feedzy-rss-feeds-import.php

Acceptance Criteria

  • Same import job cannot run concurrently
  • Lock is always released after job completes (success or error)
  • Skipped jobs are logged with job title and ID
  • Different import jobs can still run in parallel
  • Lock expires after 10 minutes even if cleanup fails (safety net)

Priority: High — prevents duplicate imported posts
Regression risk: Low — worst case a job is skipped once, retries on next cron cycle

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions