Skip to content

MailPoet sync: bug when course name is larger than MailPoet's Segment Name DB column max length #7925

@mlaetitia

Description

@mlaetitia

We're seeing Sensei's MailPoet sync job (sensei_background_job_stateful) fail in an infinite retry loop when a course title generates a segment name longer than MailPoet's wp_mailpoet_segments.name column limit.

The flow:

  1. Sync_Job::run_batch() calls Repository::get_list_name() which generates "Sensei LMS Course: {title}"
  2. get_mailpoet_lists() returns segments keyed by the name stored in the DB (which MySQL truncated on the original INSERT)
  3. array_key_exists() fails because the full-length name doesn't match the truncated stored name
  4. create_list() tries to INSERT — MySQL truncates again — duplicate key violation
  5. The DB exception closes Doctrine's EntityManager permanently for that PHP process
  6. create_list() catches APIException, but the EntityManager is already closed — every subsequent MailPoet DB call in that batch fatals with "The EntityManager is closed"
  7. Action Scheduler marks the job as failed and retries. This repeats every minute indefinitely.

We accumulated 180k+ failed actions before catching it.

Two things that would fix this on Sensei's side:

  1. Truncate the segment name to fit within MailPoet's column limit before both the lookup (array_key_exists) and the insert (create_list). MailPoet is increasing their column to 191 but any limit can be exceeded with a long enough title.
  2. Handle the Doctrine EntityManager closure gracefully. When create_list() fails, the EntityManager is dead for the rest of the request. The sync should detect this and bail out of the batch cleanly instead of continuing to call MailPoet APIs that will all fail.

Relevant code:

  • includes/mailpoet/class-sync-job.phprun_batch() lines 48-61
  • includes/mailpoet/class-main.phpcreate_list() lines 233-245
  • includes/mailpoet/class-repository.phpget_list_name() line 76

We've applied a workaround on our end (increased the wp_mailpoet_segments.name column limit ) but this should likely be fixed upstream as it will still fail if the title is large enough .

Steps to Reproduce

  1. You need both sensei and mailpoet installed / configured on the site
  2. Create a new Course with a really long name (anything over 80 characters would work)
  3. Check the Scheduled Actions page
  4. You'll notice that the Failed list will start growing as this job tries to create a segment with the course name BUT the course name is larger than the segment name column size in the DB

What I Expected

I would expect the job to consider the max length of the DB column and search for a truncated value of the course name (if larger than the limit) to make sure that it indeed finds a segment for that course if one has been created.

What Happened Instead

It keeps searching for the full course name in segments and can't find it. hence it fails and keeps retrying.

PHP / WordPress / Sensei LMS version

Sensei: Woo Paid Courses extension from WooCommerce.com
Latest (tested up to PHP 8.5, WordPress 7.0, but also with PHP 8.5 and WP 6.9).

Browser / OS version

Tested in Zen (Firefox) and Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions