Race between parallel account fetch jobs leaves email permanently stuck in "Being Imported" (no sender/recipients, never retried)
Versions: EspoCRM 10.0.3 (latest), PHP 8.4.23, MariaDB 12.3.2, official Docker image.
Steps to reproduce
Expected behavior
Both imports succeed (Message-ID dedup relates the second import to the existing email record), or the failed import is retried — the DB error explicitly says "try restarting transaction". At minimum, fetch_data.lastUID should not advance past a message whose import failed.
Actual behavior
Logs: Espo log lines above (data/logs); no web-server or browser-console errors; the failure is entirely in the scheduled job.
Versions: EspoCRM 10.0.3 (latest), PHP 8.4.23, MariaDB 12.3.2, official Docker image.
Steps to reproduce
- Create two users, each with an active personal Email Account (Personal Email Accounts) fetching from mailboxes on the same mail server.
- Keep the scheduled job "Check Personal Email Accounts" at its default ~1-minute frequency; ensure both accounts' fetch jobs can run concurrently (default job pool).
- Send one external email addressed to both users (user A in To, user B in Cc).
- Wait for both fetch jobs to import the message in overlapping runs. It is a timing race — with a shared busy mailbox it occurs regularly (observed twice in 4 days in production); sending several multi-recipient messages at once raises the odds.
- Check data/logs/espo-*.log for Import message error, and run:
SELECT id, status FROM email WHERE deleted = 0 AND status = 'Being Imported';
Expected behavior
Both imports succeed (Message-ID dedup relates the second import to the existing email record), or the failed import is retried — the DB error explicitly says "try restarting transaction". At minimum, fetch_data.lastUID should not advance past a message whose import failed.
Actual behavior
- The losing import aborts mid-save:
ERROR: (HY000) Import message error. EmailAccount <id>.
PDOException: SQLSTATE[HY000]: General error: 1020 Record has changed since last read in table 'email_user'; try restarting transaction - The exception is only logged; the UID is message is never retried.
- The email record is permanently half-written: status='Being Imported', from_email_address_id=NULL (while from_string is set), zero rows in email_emaentity_team links soft-deleted, no email_user row for the crashed account's user (that user cannot see the email).
- UI: detail view shows empty From/To/Cc. Re from the DB afterwards; only manual SQLrepair plus re-reading the IMAP headers restores the record.
Logs: Espo log lines above (data/logs); no web-server or browser-console errors; the failure is entirely in the scheduled job.

Comment