# Lock issue with segment update

**URL:** https://forum.mautic.org/t/lock-issue-with-segment-update/30915
**Category:** Product Support
**Created:** [February 16, 2024, 9:34am UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915 "2024-02-16T09:34:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![olivierlambert](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/olivierlambert/32/7635_2.png) [@olivierlambert](https://forum.mautic.org/u/olivierlambert)
#### Post date: [February 16, 2024, 9:34am UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/1 "2024-02-16T09:34:21Z")

</div>

**Your software**  
My Mautic version is: 5.0.3  
My PHP version is: 8.2  
My Database type and version is: MariaDB 10.5

**Your problem**  
My problem is: when doing `/usr/bin/php8.1 bin/console mautic:segments:update` the command fails.

These errors are showing in the log:

```auto
/usr/bin/php8.1 bin/console mautic:segments:update

In ModeratedCommand.php line 161:
                                                                       
  flock(): Argument #1 ($stream) must be of type resource, bool given 

```

Steps I have tried to fix the problem:  
Since it seems related to a file lock issue, I tried with lock by pass and it worked! So it seems there’s a hiccup with the PID file, but I don’t know how to fix it.

```auto
/usr/bin/php8.1 bin/console mautic:segments:update --bypass-locking
Rebuilding contacts for segment…
0 total contact(s) to be added in batches of 300
0 total contact(s) to be removed in batches of 300
0 contact(s) affected

```

---

<div class="post-metadata">

### Author: ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)
#### Post date: [February 19, 2024, 2:00pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/2 "2024-02-19T14:00:15Z")

</div>

Does segments update run via cron also? The issue you are facing indicates that there could be another segments:update run on the system.

Make sure permissions on the filesystem are correct and no other process is running the segments:update.

---

<div class="post-metadata">

### Author: ![olivierlambert](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/olivierlambert/32/7635_2.png) [@olivierlambert](https://forum.mautic.org/u/olivierlambert)
#### Post date: [February 19, 2024, 4:48pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/3 "2024-02-19T16:48:53Z")

</div>

Hi @mzagmajster !

Yes, they are:

```auto
1,11,21,31,41,51 * * * * cd /path/to/mautic && /usr/bin/php8.1 bin/console mautic:segments:update > /dev/null

```

But I have the error regardless when I’m doing the command. I checked and it seems I have no “stuck” segment-update command while typing it manually. Do you know where to look about the lock file path so I can double check nothing is wrong in the folder?

---

<div class="post-metadata">

### Author: ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)
#### Post date: [February 19, 2024, 6:02pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/4 "2024-02-19T18:02:15Z")

</div>

What is mostly likely happening is that you try to run the command while cron is executing.

If you disable the cron and then run the command again, do you still have the issue described above. If yes, then most likely permissions on the filesystem are not set correctly.

---

<div class="post-metadata">

### Author: ![olivierlambert](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/olivierlambert/32/7635_2.png) [@olivierlambert](https://forum.mautic.org/u/olivierlambert)
#### Post date: [February 19, 2024, 6:29pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/5 "2024-02-19T18:29:50Z")

</div>

Disabling the action in the crontab doesn’t change anything at all. Regarding permissions, I don’t know where to look exactly.

---

<div class="post-metadata">

### Author: ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)
#### Post date: [February 19, 2024, 7:00pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/6 "2024-02-19T19:00:51Z")

</div>

Some files have to be owned by the right user. Usually that user is www-data, but it really depends on your server config.

Anyway cronjob for segments needs to be run by www-data user and when you are executing the segments:update command you also have to watch out that you are executing it as www-datra user.

I cannot provide you the exact commands to try since they depend on server configuration, but this should give you an angle to explore.

---

<div class="post-metadata">

### Author: ![olivierlambert](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/olivierlambert/32/7635_2.png) [@olivierlambert](https://forum.mautic.org/u/olivierlambert)
#### Post date: [February 21, 2024, 2:44pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/7 "2024-02-21T14:44:02Z")

</div>

I have www-data all around and all permissions are OK for this user in the Mautic folder.

edit: it was the case initially, but I re-did a `chown www-data:www-data -R mautic` and now it seems to work. Well, it’s weird those permissions changed by themselves at some point, but I would consider it as solved. Thanks for the tip @mzagmajster !

---

<div class="post-metadata">

### Author: ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)
#### Post date: [February 21, 2024, 6:04pm UTC](https://forum.mautic.org/t/lock-issue-with-segment-update/30915/8 "2024-02-21T18:04:08Z")

</div>

If the permissions have changed, the cause can be because cron is running as different user.

Make sure to run mauticcron jobs as www-data
