Skip to content

1.3.0: atomic database queue and global worker lock - #4

Merged
tikhomirov merged 2 commits into
mainfrom
fix/atomic-database-queue
Nov 11, 2026
Merged

tikhomirov merged 2 commits into
mainfrom
fix/atomic-database-queue

Conversation

@tikhomirov

Copy link
Copy Markdown
Owner

Jobs of the database driver were kept in one wp_options array and rewritten without locking (and read through the persistent object cache). With parallel workers (WP-Cron + loopback + admin) jobs were lost and the same job ran dozens of times.

  • {prefix}queue_jobs table, pop() claims with a conditional UPDATE; 1.2.x option jobs migrated.
  • One DB-row worker lock for all queues.
  • wp queue work --all --max-time.
  • Daemon mode: no WP-Cron scheduling, stale wp_queue_process events removed; no spawn_cron() with DISABLE_WP_CRON.
  • Base64 payloads (PostgreSQL).
  • Tests: race between two workers, stale reclaim, legacy migration, 4 parallel processes x 120 jobs (SQLite). Smoke-tested on PostgreSQL via PG4WP: 4 parallel wp-cli workers x 90 jobs, 0 duplicates.

- Database driver keeps jobs in {prefix}queue_jobs; pop() claims a row with a
  conditional UPDATE, so parallel workers can neither lose nor repeat jobs
  (the wp_options array was rewritten without locking and read through the
  persistent object cache).
- 1.2.x jobs stored in wp_options are migrated on first use.
- One DB-row worker lock for all queues ({prefix}queue_locks), used by
  wp_queue_process, REST process, wp queue work and the daemon.
- wp queue work --all --max-time for system cron.
- Daemon mode removes stale wp_queue_process events; dispatch() does not
  spawn_cron() when DISABLE_WP_CRON is set.
- Payloads base64-encoded (PostgreSQL text rejects NUL bytes).
- Tests on a real SQL engine (SQLite): race between two workers, stale
  reclaim, legacy migration, 4 parallel worker processes x 120 jobs.
@tikhomirov
tikhomirov merged commit ce2e041 into main Nov 11, 2026
5 checks passed
@tikhomirov
tikhomirov deleted the fix/atomic-database-queue branch November 13, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant