I'm sending mails over drupal_mail with a cron queue. There are 5 parrallel ultimate cron worker jobs that all process the queue items (mails to be sent). If i do tests with hundreds of mails then in case of about 2% i get the following error.

Disabling the mail_tracking module will make the error go away.

Jul 23 10:30:17 <servername> drupal: http://<servername>|1406104217|cst_mail_cron|85.25.214.136|http://<servername>/bgp-start/uc-queue_cst_send_mail_5/3a2add577a32fb5600b7e19fdeb8ea43||0||Queue item 18870 from queue cst_send_mail failed with message exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'b96b019690baf7e7aa00114997cf40ac' for key 'PRIMARY'' in <path_to_httpdocs>/includes/database/database.inc:2171#012Stack trace:#012#0 <path_to_httpdocs>/includes/database/database.inc(2171): PDOStatement->execute(Array)#012#1 <path_to_httpdocs>/includes/database/database.inc(683): DatabaseStatementBase->execute(Array, Array)#012#2 <path_to_httpdocs>/includes/database/mysql/query.inc(36): DatabaseConnection->query('INSERT INTO {ma...', Array, Array)#012#3 <path_to_httpdocs>/sites/all/modules/mail_tracking/includes/mail_tracking.mail.inc(426): InsertQuery_mysql->execute()#012#4 <path_to_httpdocs>/sites/all/modules/mail_tracking/includes/mail_tracking.mail.inc(91): MailTrackingMailSystem->saveToken(Array)#012#5 <path_to_httpdocs>/includes/mail.inc(183): MailTrackingMailSystem->mail(Array)#012#6 <path_to_httpdocs>/sites/all/modules/Custom/cst_mail_cron/cst_mail_cron.module(99): drupal_mail('mimemail', 'cst_mail_cron_d...', 'dummy@gmx-to...', Object(stdClass), Array, 'Dummy test

Comments

matthijs’s picture

It looks like the MD5 hash of the message id, recipient and request time isn't unique enough.
Is it possible that you have the same recipient twice? Otherwise I have to improve the token generation and store the token before the actual rewrite...

fox_01’s picture

This error comes from a test where i have generated 500 queue items that were sent with drupal_mail(). There were all the same message ids and same recipients but only a few % errors occur

deggertsen’s picture

matthijs’s picture

Assigned: Unassigned » matthijs
Priority: Normal » Major

Yes, I will :-)

matthijs’s picture

@deggertsen: I didn't notice it before, but it you've got a different duplicate key error then fox_01. Please open a new issue for this one...

deggertsen’s picture

Referencing my possible related issue. Thanks for looking into this Matthijs

  • Matthijs committed a2d4378 on 7.x-1.x
    Issue #2308065: Fixed integrity constraint on duplicate tokens when...
matthijs’s picture

Status: Active » Fixed

The latest dev should fix this issue, please give it a try!

matthijs’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.