# Campaign can't add 1 contact on rebuild and hangs

**URL:** <https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668>\
**Category:** Product Support\
**Created:** [July 21, 2023, 11:04am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668 "2023-07-21T11:04:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gradualchange](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@gradualchange](https://forum.mautic.org/u/gradualchange)\
**Post date:** [July 21, 2023, 11:04am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/1 "2023-07-21T11:04:10Z")

</div>

**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:

```auto
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?

Thanks.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [July 21, 2023, 11:10am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/2 "2023-07-21T11:10:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gradualchange](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@gradualchange](https://forum.mautic.org/u/gradualchange)\
**Post date:** [July 21, 2023, 11:18am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/3 "2023-07-21T11:18:37Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Madlen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/madlen/32/15300_2.png) [@Madlen](https://forum.mautic.org/u/Madlen)\
**Post date:** [July 22, 2023, 3:12pm UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/4 "2023-07-22T15:12:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [July 23, 2023, 7:19am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/5 "2023-07-23T07:19:23Z")

</div>

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

> <https://github.com/mautic/mautic/pull/11318>
>
> \<!-- ## Which branch should I use for my PR?
> 
> Assuming that:
> 
> a = current ma…jor release
> b = current minor release
> c = future major release
> 
> \* a.x for any features and enhancements (e.g. 5.x)
> \* a.b for any bug fixes (e.g. 4.4, 5.1)
> \* c.x for any features, enhancements or bug fixes with backward compatibility breaking changes (e.g. 5.x) --\>
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | \[\]
> | New feature/enhancement? (use the a.x branch) | \[\]
> | Deprecations? | \[\]
> | BC breaks? (use the c.x branch) | \[\]
> | Automated tests included? | \[\] 
> | Related user documentation PR URL | mautic/mautic-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation#... 
> | Issue(s) addressed | Fixes https://github.com/mautic/mautic/issues/11061
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "4.x" branch.
> \--\>
> 
> \#### Description:
> 
> Ugly looping issue while campaign rebuild use with \`Allow contacts to restart the campaign \`
> 
> \<!--
> Please write a short README for your feature/bugfix. This will help people understand your PR and what it aims to do. If you are fixing a bug and if there is no linked issue already, please provide steps to reproduce the issue here.
> \--\>
> 
> \#### Steps to test this PR:
> 
> \<!--
> This part is really important. If you want your PR to be merged, take the time to write very clear, annotated and step by step test instructions. Do not assume any previous knowledge - testers may not be developers.
> \--\>
> 1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs \[here\](https://contribute.mautic.org/contributing-to-mautic/tester))
> 2. Add to segment two contacts by filter not manually
> 3. Create campaign with segment
> 4. Rebuild segment 
> 5. Then manually remove from campaign one contact
> 6. Then rebuild campaign 
> 7. See rebuild looping
> 8. After PR should work properly
> 
> \<!--
> If you have any deprecations, list them here along with the new alternative.
> If you have any backwards compatibility breaks, list them here.
> \--\>
> 
> 
> \<a href="https://gitpod.io/#https://github.com/mautic/mautic/pull/11318"\>\<img src="https://gitpod.io/button/open-in-gitpod.svg"/\>\</a\>

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

---

<div class="post-metadata">

**Author:** ![gradualchange](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@gradualchange](https://forum.mautic.org/u/gradualchange)\
**Post date:** [September 7, 2023, 12:46pm UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/6 "2023-09-07T12:46:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gradualchange](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@gradualchange](https://forum.mautic.org/u/gradualchange)\
**Post date:** [September 8, 2023, 2:39am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/7 "2023-09-08T02:39:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mauticcy](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mauticcy](https://forum.mautic.org/u/mauticcy)\
**Post date:** [January 2, 2024, 12:06am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/8 "2024-01-02T00:06:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gradualchange](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@gradualchange](https://forum.mautic.org/u/gradualchange)\
**Post date:** [January 2, 2024, 1:43am UTC](https://forum.mautic.org/t/campaign-cant-add-1-contact-on-rebuild-and-hangs/28668/9 "2024-01-02T01:43:35Z")

</div>

I probably would have just applied this patch to this one file: [Fix campaign looping issue by kuzmany · Pull Request #11318 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/11318/commits/860815643f5c090626d55071d59e3eb879929e28)
