Updating metadata is a non thread-safe operation
|Reported by:||aszepeshazi||Owned by:|
|Priority:||normal||Milestone:||Long Term Discussion|
Description (last modified by ewinslow)
When two or more parallel threads try to update the same metadata on the same object, the results are unpredictable.
- Go to https://gist.github.com/1556812 , download the "parallel_test.php" script and drop it into your Elgg installation's root directory.
- Hit http://your-elgg-site/parallel_test.php in your browser a couple of times, and watch the php error log. A counter should increase one by one, showing how many times the object metadata was updated.
- To test the behavior of parallel threads, use apache benchmark. In a console, run "ab -n 100 -c 10 http://your-elgg-site/parallel_test.php" and watch the log. You'll see at some point the single integer type property turning into an array.
"I believe this is a race condition - 2 PHP processes are creating the metadata at the same time. If we didn't support arrays, we could put a unique key on entity_guid and metadata name and let the database catch this. Because we do allow arrays, we try to catch this in PHP which creates the race condition."
Change History (8)
comment:3 Changed 12 months ago by ewinslow
- Description modified (diff)
- Difficulty set to moderate
- Milestone changed from Needs Review to Long Term Discussion