# Race condition Gateway Tag Change Script — shared tag reads- memory tag

**URL:** <https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [November 13, 2026, 7:50pm UTC](https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845 "2026-11-13T19:50:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saipeddireddy10](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@saipeddireddy10](https://forum.inductiveautomation.com/u/saipeddireddy10)\
**Post date:** [November 13, 2026, 7:50pm UTC](https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845/1 "2026-11-13T19:50:20Z")

</div>

Two Gateway Tag Change Scripts fire simultaneously when the PLC changes shift:

```python
PLC
 |
 |── Shift tag changes ──► Script A
 | writes memoryTag(Mtag1)
 |
 |── Machine status changes ──► Script B
                                    reads memoryTag(Mtag1)

```

**The race**

Both scripts fire at the same instant. Script B reads the memory tag before Script A has finished writing it.

```python
Script A Script B
         
        | |
starts writing starts reading
memoryTag memoryTag
        | |
        | reads OLD value ← stale
        | |
finishes writing writes DB row
memoryTag (new value) with OLD Mtag1 value

```

Script B gets the old value. The DB row is filed under the wrong production period.

**Question**

Is there a supported pattern to guarantee Script B reads the memory tag only after Script A has finished writing it?  
Is there any better Approach to achieve it

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 13, 2026, 8:01pm UTC](https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845/2 "2026-11-13T20:01:02Z")

</div>

Is it always sequential? Any reason not to start Script B after Script A in the same gateway script to completely sidestep having 2 scripts running at once?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 13, 2026, 8:05pm UTC](https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845/3 "2026-11-13T20:05:44Z")

</div>

Either that or use an intermediate tag that is both "script a has finished and machine status has changed"

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 13, 2026, 8:11pm UTC](https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845/4 "2026-11-13T20:11:04Z")

</div>

Best practice is not to write to the same tag you are reading from, for the same reasons the OP is demonstrating.

~~saipeddireddy10, if you can tell us what you're trying to do, we can probably give you a better answer.~~ nvm, I think I see what you're trying to do.  
What are you writing with script A?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 13, 2026, 9:50pm UTC](https://forum.inductiveautomation.com/t/race-condition-gateway-tag-change-script-shared-tag-reads-memory-tag/117845/5 "2026-11-13T21:50:03Z")

</div>

You will always have race possibilities like this since Ignition is highly multi-threaded and parallelized. The best way to ensure sequential behavior is to use just one script.

I wouldn't try to write the production period in the machine status script. Just write the new status and timestamp. The timestamp implicitly indicates the period when looked up later.
