Commit 99bbae9
committed
bug #62199 [Workflow] State Contamination in Marking Stores due to Class-based Getter Cache (siganushka)
This PR was merged into the 7.4 branch.
Discussion
----------
[Workflow] State Contamination in Marking Stores due to Class-based Getter Cache
State Contamination in Marking Stores due to Class-based Getter Cache
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| License | MIT
The issue manifests in Marking Store configurations (e.g., `MethodMarkingStore`), tracing back to a logic flaw in the core Workflow component's state-accessing mechanism.
The `getMarking()` method caches the state-accessing Getter Closure based solely on the class name (`Subject::class`).
In a concurrent, multi-subject environment (e.g., Messenger Workers), this leads to state contamination:
A Worker processes Subject 1, successfully transitioning its state from first_place to second_place.
The cached Getter Closure is created or updated, capturing a reference or memory state related to second_place.
When the same Worker processes Subject 2 (a different instance, whose actual state is first_place in the database), the cached Getter is used.
This Getter incorrectly returns the state related to Subject 1's final marking (second_place), despite Subject 2's data being correct.
Consequently, `getMarking()` reports a marking of ["second_place":1], causing valid transitions from first_place to be incorrectly blocked.
```php
$subject1 = new Subject('first_place');
$subject2 = new Subject('second_place');
$markingStore = new MethodMarkingStore(true);
$marking1 = $markingStore->getMarking($subject1);
$marking2 = $markingStore->getMarking($subject2);
// Expected: ["first_place" => 1]
// Actual: ["first_place" => 1]
$marking1 ->getPlaces();
// Expected: ["second_place" => 1]
// Actual: ["first_place" => 1]
$marking2 ->getPlaces();
```
Commits
-------
160608d fix: fixed State contamination in marking stores due to class-based getter cacheFile tree
2 files changed
+20
-3
lines changed- src/Symfony/Component/Workflow
- MarkingStore
- Tests/MarkingStore
2 files changed
+20
-3
lines changedLines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
| 96 | + | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
128 | 145 | | |
129 | 146 | | |
130 | 147 | | |
| |||
0 commit comments