I just upgraded a site to the 7.x-1.0-beta1 version of Simplenews and am now finding that newsletters keep sending on cron runs even after they've been successfully sent already.

For example, to test this I created a new type of newsletter called 'Test' and made myself the only subscriber. I then sent a newsletter of type 'Test' which sent successfully (I got a copy in my inbox). I then manually ran cron a few times to confirm the newsletter didn't keep sending - it didn't.
All seemed fine until cron ran automatically an hour later and the newsletter was re-sent to myself.

For some reason, newsletter keep sending after they've already been successfully sent when cron runs automatically, but not when cron is run manually...

CommentFileSizeAuthor
#12 pending_condition_fix.patch1.76 KBberdir

Comments

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

Can you try to reproduce this on a new site?

Has the site been upgraded from Drupal 6 or is it a new install? Since when are you using Simplenews 7.x-1.x?

Check if there are any errors in the recent log messages, for example mail send errors or pdo exceptions.

It might be that something causes a failure between sending out the mail and updating the record in the database when cron is executed automatically. This would then result in Simplenews trying to re-send because it assumes that sending failed. We had a similar case recently.

hozt’s picture

Status: Postponed (maintainer needs more info) » Active

We experienced this same problem after upgrading. Newsletters that had been sent in the past were sent again multiple times to each subscriber after this update. I had to manually clear the simplenews_email_spool to stop the emails from being sent.

The site is a drupal 7 not an upgrade. There are no pdo errors in the log. All newsletters are marked as sent. Under the setting cron was not being used to send the emails.

Anonymous’s picture

I think I worked out the issue...

I was trying to test this on a new site but didn't want to have to wait an hour between cron runs to see if different solutions worked. I therefore setup a crontab to run cron every 2 minutes instead of using Drupal's built-in system to run cron every hour (I disabled Drupal's built-in cron altogether). When I did this, I stopped getting the duplicate newsletters.

I think this must be the know bug as mentioned on the project page regarding using 'Poormanscron', although I didn't pick up on it sooner as I didn't realise that the cron built-in to Drupal 7 was still called 'Poormanscron'...

If this fixes this issue for hoZt as well then I think we can close this issue. I would recommend though re-wording the bug on the project page to mention Drupal 7's built-in cron (as accessed by /admin/config/system/cron) and that that is what's meant by 'Poormanscron'.

hozt’s picture

Thanks for looking into this.

Can you clarify what the fix is? I switched the setting to send the newsletter through the cron earlier today, but ran the cron manually to initiate the send. It sent all the emails as regular, but then started sending out duplicate emails afterwards. I had to once again manually clear the table simplenews_email_spool table and disabled the mail system through devel. It looks like the emails are not being removed from simplenews_email_spool.

Anonymous’s picture

@hoZt:

Go to /admin/config/system/cron and set 'Run cron every' to 'Never' (this disables the 'Poormanscron' in Drupal).

Now you need to setup cron on your server (i.e. the 'proper' way).
I can't assist you here, but this page should be able to provide the necessary steps for your server type: http://drupal.org/node/23714 (see the sub-pages at the bottom for different server setups (e.g. cPanel)).

Hope that helps.

Anonymous’s picture

Ok, maybe that didn't work after all...

I created a test newsletter node and sent it at 1:04pm.
At 2:00pm, cron ran and the newsletter was sent.
At 3:00pm, cron ran and no duplicate newsletters were sent (yay!).
At 4:00pm, cron ran and a duplicate newsletter was sent :(

I'm wondering if I may have set 'Mail spool expiration' to 'Immediate' before 3pm, but then set it to '1 day' before 4pm... I can't remember, so I've set it to 'Immediate' again, cleared the simplenews_mail_spool table and created a new newsletter to test. Will report back in a few hours...

Anonymous’s picture

Ok, it seems to be working again. I'm not sure if the Mail Spool Expiration was the cause of the duplicates at 4pm, but I know that I've since had it set to Immediate expiration and so far no duplicates (after 2 cron runs).

hozt’s picture

It looks like the mail spool expiration setting is the issue and not the cron. Changing this to expire the spool immediately prevents the duplicates from being sent.

This is a new bug that was not in the 2012-01-04 dev version that we were running previous to this version.

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

I'm unable to reproduce this with some basic tests.

Can you please do the following?

1. Change the expire setting to something else than immediate
2. Send a (test with just a few example recipients) newsletter
3. Provide an export of your simplenews_mail_spool table. A few example rows are enough and you can replace the mail address with a dummy one.

status should be 2 and error 0, do you have different values?

When you enable debug logging in the simplenews mail settings, is there anything unusual?

hozt’s picture

I changed the expire setting to expire after a week and tested sending to a small group (7) and the simplenews_mail_spool table did get the right status for the emails. There were no errors in the log.

pezia’s picture

The query that fills the send spool seems wrong to me.
In simplenews_get_spool() the query generated is:
SELECT s.* FROM {simplenews_mail_spool} s WHERE ( (status = :db_condition_placeholder_0) OR (status = :db_condition_placeholder_1) OR (s.timestamp < :db_condition_placeholder_2) ) ORDER BY s.timestamp ASC

I think it should be sg. like status = SIMPLENEWS_SPOOL_PENDING OR (status = SIMPLENEWS_SPOOL_IN_PROGRESS AND timestamp< expiration_time)

foreach ($statuses as $status) {
    if ($status == SIMPLENEWS_SPOOL_IN_PROGRESS) {
      $in_progress_and = db_and();
      $in_progress_and->condition('status', $status);
      $in_progress_and->condition('s.timestamp', simplenews_get_expiration_time(), '<');
      $status_or->condition($in_progress_and);
    } else {
      $status_or->condition('status', $status);
    }
  }
berdir’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.76 KB

Uh, you are of course right!

I had assumed something like that but haven't had time to confirm it.

The attached patch adds a test for this and fixes it. Please test.

berdir’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
pezia’s picture

Thx. Works as expected.

berdir’s picture

Status: Needs review » Fixed

Thanks for testing, commited and pushed.

Jose Chaves’s picture

It would be nice to have an upgrade including this issue solved, for the rest of us that are not so familiar with patching.
So, I still have my simplenews module malfunctioning, continuously sending emails to 10k addresses, like it happened last night.

Thanks in advance.

berdir’s picture

This is fixed in the dev snapshot, you do not need to patch anything.

Status: Fixed » Closed (fixed)

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