Bug #18253
closedDuplicate entry on cache_pagesection on reloading twice
0%
Description
If I reload a page in the frontend twice or two or more persons access the same page at almost the same time, an SQL error in tabe cache_pagesection is show.
That's a concurrence problem incorrectly fixed in http://bugs.typo3.org/view.php?id=4581
That's a concurrence problem is in that piece of code.
Two or more users can do the insert at same time . There aren't transactions or another way to control concurrence and then we can't assume that condition ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) is true when a process do the insert because another process could do the insert before.
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvar_hash, $dbFields);
if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
$dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
$dbFields['mpvar_hash'] = $mpvar_hash;
// HERE ===> two or more execs at the same time
$GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
}
(issue imported from #M7591)
Files
Updated by Manuel Rego Casasnovas over 16 years ago
Thinking about this very important concurrence problem I've developed a solution that doesn't depend on database.
But in my solution there is the same database error but I hide the error and I do an UPDATE to get the expected result.
I've added a new patch bug_0007591_without_on_duplicate_key_update.patch with this new solution.
Updated by Jo Hasenau over 16 years ago
The same error happens if you reload the page with header(location: blah)
I do this i.e. after saving some incoming data of a form to avoid users resending the very same data by pressing F5.
A quick and dirty workaround was to insert sleep(1) before the header command but I don't think this could be a real solution.
Updated by Michael Stucki over 16 years ago
Which version did you use for reproducing this problem? Notice that in TYPO3 4.2 beta2 it should be solved, otherwise we should fix this asap.
Updated by Alexander Bohndorf over 16 years ago
I think that the patch from Manuel does not really fix the problem but it hides only the resulting error.
I added a patch which uses the INSERT INTO ... ON DUPLICATE KEY UPDATE Statement to combine the insert and update operation as one atomar operation without using transactions.
See the file patch-insert-on-duplicate-key
Updated by Martin Holtz over 15 years ago
Updated by Christian Kuhn over 14 years ago
Duplicate of #19621 which already has a pending patch in core list.