Symptom: when sending large numbers of emails in one go, multiple copies could be delivered to the recipients. The threshold for what constitutes a 'large number of emails' will differ depending on the speed of your onCourse Server hardware and the speed of your mail server. We expect this to vary between 25 (remote slow mail server) and 2000 (local good quality mail server).
Details: A mail processing thread wakes up every minute to deliver emails created within the onCourse system. This queuing mechanism was created so that your onCourse server could be shut down, your mail server be offline or your internet connection down, and when services are restored all queued emails are sent without missing any emails.
However, if the number of emails to be sent was large, the sending of those emails would not complete within one minute and a second thread would wake up to start sending emails to the queue. In itself this would not be a problem since the first thread would be marking emails as 'delivered' and saving that status to the database as soon as each email is sent. However the first thread already had loaded the list of emails into memory, so when the second thread started to pass the first one with regard to which record it was trying to send (as it would since it had less work to do) it would then started sending emails that the first thread would shortly also deliver to. This would then deliver duplicates to some of the recipients in the original list. Since email sending wakes up for delivery once a minute, the problem would only occur if email delivery took more than one minute. If email delivery continued into the third minute, then some users might get 1 email, others 2 and others 3.
We have corrected this problem in two ways:
1. only one email sending thread is created at a time, even if it takes a long time to finish running. This in itself is sufficient to fix the problem.
2. each email to be sent is refetched (in batches of 25) before sending, to recheck that its status hasn't already changed to sent. This will limit the problem to at most 25 emails which will usually be sent within one minute. This was done to ensure that even if some future issue allows multiple threads to run at once we have another way to limit the problem.
We strongly recommend upgrade for all customers on onCourse versions 2.1 or higher.