Campaign can't add 1 contact on rebuild and hangs

Your software
My Mautic version is: 4.4.9
My PHP version is: 7.4.3
My Database type and version is: 8.0.31-0ubuntu0.20.04.1

Your problem
My problem is: When I run php bin/console mautic:campaigns:rebuild -vvv, the campaign fails to add a single contact, and then hangs forever.

These errors are showing in the log:

Rebuilding contacts for campaign 34
1 total contact(s) to be added in batches of 300
50,103/50,103 [============================] 100%

Steps I have tried to fix the problem:

Turning off campaign 34. This at least let me process my other campaigns, but if this mystery contact gets added to another campaign later on, it will kill that campaign too.

I have two questions:

  1. How do I find the mystery contact?
  2. How do I know why this is happening?


can you run the command mautic:campaigns:update -i 34 and then have a look at the logs tail -f /var/log/nginx/mautic.* to see the output, also have a look at the Mautic logs inside the UI as well

So immediately after posting this, I found the contact by creating a segment that excluded the campaign from the segment the campaign was running on, and put the contact in the campaign manually. I had a look at the contact and there does not seem to be anything amiss about them.

For now, problem resolved? The nginx error doesn’t seem related…

Hi @gradualchange , this can happen when you manually remove a contact from a campaign but not the starting segment, where the contacts is still in.

Hi, as far as I know this issue is fixed for Mautic 5.

You can merge this PR, it would fix your problem.

Thanks! I haven’t tested it yet, but I’ll have to think about the best way to apply this patch to the codebases perpetually until we get to Mautic 5. Is there a way to run a hook automatically after updating Mautic? My understanding is the patch would get overridden by every subsequent update.

Alright, I gave it a shot. It seems to have worked! Replacing the LeadRepository.php file stopped the loop on several of my instances! Thanks for that.

Hi, which file did you replace exactly? I have the same issue but there are several files with same name. I’m on 4.4.10

I probably would have just applied this patch to this one file: Fix campaign looping issue by kuzmany · Pull Request #11318 · mautic/mautic · GitHub