Filing this as a support request since I'm not sure if it's a bug or not.
Every once in a while I see an error like this in my log:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '98.66.59.2' for key 'PRIMARY': INSERT INTO {httpbl} (hostname, status, expire) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 98.66.59.2 [:db_insert_placeholder_1] => 0 [:db_insert_placeholder_2] => 1321419035 ) in _httpbl_cache_set() (line 610 of /home/name/public_html/sites/all/modules/httpbl/httpbl.module).
I don't, however, see a row in the httpbl table with a hostname value of 98.66.59.2 so I'm not sure why there appears to be a duplicate entry. What might be going on here?
Comment | File | Size | Author |
---|---|---|---|
#24 | path_integrity_constraint_violation.patch | 654 bytes | gerson.analista |
#8 | httpbl.module.patch | 684 bytes | sah62 |
Comments
Comment #1
deekayen CreditAttribution: deekayen commentedIs that MySQL or something else?
Comment #2
sah62 CreditAttribution: sah62 commentedYes, I'm using a MySQL database.
Comment #3
sah62 CreditAttribution: sah62 commentedCould this be related to the race condition described in #723358: PHP Warning: Duplicate entry <snip> for key 1\nquery: INSERT INTO httpbl (hostname, status, expire) VALUES <snip>?
Comment #4
sah62 CreditAttribution: sah62 commentedIf this code can produce a race condition:
Can the race condition be avoided by doing a db_merge instead?
Comment #5
sah62 CreditAttribution: sah62 commentedI've been running the code change described above and it seems to have eliminated the problem with trying to insert a value before the row has been deleted, causing an integrity constraint violation. I'm changing this from a support request to a bug report in the hope that the fix gets picked up. It should work for all supported databases if I'm reading the D7 database API documentation correctly.
Comment #6
bryrock CreditAttribution: bryrock commentedsah62, There's some history to this issue which I'm not personally familiar with and haven't had adequate time to investigate. While it's not a widely reported problem, those who have reported it seemed repeatedly plagued by it. I've been busy with the day job and it may be some time before I can look into this further. In the meantime, could you submit a patch file? I'd like to try it out.
Comment #7
sah62 CreditAttribution: sah62 commentedSure, I'll see what I can do to produce a patch.
Comment #8
sah62 CreditAttribution: sah62 commentedPatch file attached.
Comment #9
sah62 CreditAttribution: sah62 commentedThis issue still exists in the 7.x-1.0-rc5 release.
Comment #10
bryrock CreditAttribution: bryrock commentedYes, I know. I committed it earlier today but haven't pushed it up, yet. Slipped out to the movies. Coming soon.
Comment #11
bryrock CreditAttribution: bryrock commentedThis has been committed to 7.x-1.x-dev and is in 7.x-1.0-rc6.
Thanks for this patch (from nearly a year ago). Sorry it took me so long to get it added.
Comment #13
mrsean CreditAttribution: mrsean commentedtl;dr: Is there a reason that you aren't attempting to catch any exceptions, like the code on the Drupal docs page for transactions (https://drupal.org/node/355875) shows?
Full Post:
I'm using the latest version of the module 7.x-1.0, with a date of 2012-Nov-21.
I am having similar issues as sah62, specifically I'm sending multiple emails via drush when this issue occurs, and then they stop getting sent when the problem occurs:
Drush command terminated abnormally due to an unrecoverable error. [error]
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '127.0.0.1' for key 'PRIMARY': INSERT INTO {httpbl}
(hostname, status, expire) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array
(
[:db_insert_placeholder_0] => 127.0.0.1
[:db_insert_placeholder_1] => 0
[:db_insert_placeholder_2] => 1391502301
)
in _httpbl_cache_set() (line 607 of /var/www/html/sites/all/modules/httpbl/httpbl.module).
My guess is that the following is happening:
cron deletes the 127.0.0.1 entry from httpbl table.
Then, multiple emails getting sent at the same time from my drush command causes multiple httpbl lookups.
httpbl doesn't have anything in the httpbl table (as the entry was just deleted by cron), so the httpbl module makes multiple httpbl table insert attempts for 127.0.0.1, one for each email being sent, all at the same time.
Since IP is the primary key for all of these insert attempts, all but one of these insert attempts fail, throwing exceptions which crash running Drupal sessions and anything drupal is currently doing..... such as sending my emails via drush.
That's just my guess as to whats happening... but if anyone has a different hypothesis, I'm all ears.
Is there a reason that you aren't attempting to catch any exceptions, like the code on the Drupal docs page for transactions (https://drupal.org/node/355875) shows?
Comment #14
freeform.steph CreditAttribution: freeform.steph commentedWe have the latest version installed (7.x-1.0), have checked the code and see that the patch has been applied, but unfortunately we are still getting this error.
Someone else has also reported this problem, their request should maybe be marked duplicate and this one re-opened: https://www.drupal.org/node/2311539
Comment #15
uno CreditAttribution: uno commentedComment #16
cayerdis CreditAttribution: cayerdis commentedI am using the latest version of the module. However, I still experience this problem. Here it is my log:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '205.144.215.109' for key 'PRIMARY': INSERT INTO {httpbl} (hostname, status, expire) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 205.144.215.109 [:db_insert_placeholder_1] => 2 [:db_insert_placeholder_2] => 1412442511 ) in _httpbl_cache_set() (line 607 of /public_html/sites/all/modules/httpbl/httpbl.module).
Comment #17
uno CreditAttribution: uno commentedSame here, just different IPs (and 1416174181), even after patch aplication.
Comment #18
michaelgiaimo CreditAttribution: michaelgiaimo commentedAdd me to the list. Dev version doesn't help either.
Comment #19
manikandan.btech CreditAttribution: manikandan.btech commentedI too facing the same problem. I'm using latest version of this module.
Comment #20
blind486 CreditAttribution: blind486 commentedI also got this error, everyday. latest version.Using Http:BL 7.x-1.0
Comment #21
netgeek123 CreditAttribution: netgeek123 commentedSame as everyone else.
Comment #22
mparker17I'm also getting this error occasionally.
I noticed the code causing the error is a
db_merge()
call, which should work. I'm guessing that means that there's a concurrency issue. I guess we can use Drupal's Locking mechanism to ensure two requests don't try to run adb_merge()
query at the same time.I'll look into writing a patch tomorrow, but I'm leaving the issue unassigned in case someone else gets to it first :P
Adding "Needs issue summary update" tag since the issue summary doesn't conform to the template.
Unassigning @bryrock as he's been assigned for ~3 years.
Updating Version as I'm seeing this on
7.x-1.0
.Comment #23
bryrock CreditAttribution: bryrock as a volunteer commented@mparker17, I actually do check in now and then, but if you've got a notion to write a patch, then please go for it.
Also wondering if this might relate to #2373967: Masquerading leads to deadlock - Incompatibility with masquerade module!, because otherwise I find that issue un-reproduce-able.
Comment #24
gerson.analista CreditAttribution: gerson.analista commentedI got the same error.
I made a path and the error stopped happening.
Could you help me test?
Comment #25
ron_s CreditAttribution: ron_s commentedI'll give the patch a try in just a bit... we're seeing this error quite regularly in our logs.
Comment #26
ron_s CreditAttribution: ron_s commentedWe've been running patch #24 on a live site for the past 10 days and have not seen the integrity constraint violation again. Previously we were seeing it at least 2-3 times per day.
I'm marking as 'needs review' to encourage others to test. Thanks for the patch!
Comment #27
lanvilleadmin CreditAttribution: lanvilleadmin commentedI am getting this problem as well. It happens occasionally on the site and I get the errors in the Drupal logs. I can give the log if needed.
Comment #28
everkuil CreditAttribution: everkuil commentedI added the patch #24 and the last 2 weeks we didn't see the path_integrity_constraint_violation anymore. Looks to work fine now.
Comment #29
netgeek123 CreditAttribution: netgeek123 commentedCan someone push this patch to a release????
Comment #30
ron_s CreditAttribution: ron_s commented@netgeek123, if the patch is working for you, mark it RTBC.
Module owners aren't going to release something that is still "Needs review."
Comment #31
netgeek123 CreditAttribution: netgeek123 commentedThis patch works perfectly. Thank you!
Comment #34
bryrock CreditAttribution: bryrock as a volunteer commentedI'll agree to call this "fixed." I think this code has about gone full circle. If you look back at past commits, going back to D6, this issue was #989056 and it was fixed with a db_query REPLACE (commit c75cfe8b8004e3e654623041501c978cc7f98328).
And then it blew up on somebody, again, and then it got changed to a merge, and so on, and so on.
Historically, and in theory, the only time a record got replaced was if a greylisted IP failed the challenge and became blacklisted. Otherwise, an IP either got added because they weren't in the table, or not added because they were found, and that was all that needed to happen. I think one of the problems has been that the table never really used any sort of index other than the IP address (string).
Anyway, if anyone is interested there is (finally) a D8 dev release. It's all new and radically different. The old records are now manageable "Host' entities, with core services handling the entity and storage management (no more hand-painted SQL).
The old Views reports are gone, and have been replaced by an Admin View where you can manage the hosts (if you're so inclined), including a bunch of bulk actions.
And the logging logic is all out of the way of the mainline logic. You want to log a debug message, just go ahead and do it, and a LogTrapper service then decides whether or not to actually send it, based on the config settings.
Comment #35
bryrock CreditAttribution: bryrock as a volunteer commentedFix included in release candidate.