Skip to content

Cannot send emails - cron job is hanging

edited December 2012 in Troubleshooting
Hi,
When I am trying to send out emails, the cron process freezes without actually sending anything. I did some debugging and found that the process (scheduled.php) is getting stuck while doing multithreaded cURL (Lines 231 – 258 in includes/helpers/class.amazonses.php). We run Sendy off AWS instance. PHP version 5.3.18.

Can you please help us with this issues? It's a holiday season and we do need to start emailing customers ASAP.

-- Aleksey

Comments

  • Hi Aleksey, can you clarify what you mean by 'getting stuck'?

    Also, how many emails are you sending to? What is your send rate and what tier are you on?

    Thanks.
  • Hi Ben,
    What I mean is the following:
    From UI, it looks like the campaign quickly (once the cron job starts running) gets into "sending" state, and stays in it forever (well, for more than an hour). Since I am trying to send a test batch to 10 recipients, this time seemed to me wrong, and I tried launching the cron script manually. It never ended. Then I opened your source (I am a PHP developer myself), and added several debug echo statements, which showed me that the script loops forever in class.amazonses.php. We are on production tier, daily quota 10,000 emails, 5 emails/sec.
  • Thanks for clarifying. Strange because many of our users are running Sendy on EC2 with no problems. I've also setup a micro instance with Apache/Linux before to test and was able to send successfully.

    Are you using Apache/Linux? Some used Ubuntu and was able to work as well.
  • We use Amazon Linux AMI release 2012.09 with Apache.
  • Looks like I solved the problem. I changed the following line in class.amazonses.php:
    $q2 = 'SELECT id, query_str, subscriber_id FROM queue WHERE campaign_id = '.$this->CampaignID.' LIMIT '.$ses_send_rate;

    to:

    $q2 = 'SELECT id, query_str, subscriber_id FROM queue WHERE campaign_id = '.$this->CampaignID.' LIMIT '.($ses_send_rate -1 );


  • No, scratch that - it only made it deliver some emails... Ben, can you please help us to fix this issue?
  • I think I - finally! - found the root of the problem. Looks like with certain combinations of OS versions/ PHP versions the call curl_multi_select behaves strangely - it always returns -1. This caused the loop in the class.amazonses.php to be executed forever. The official recommendation is that if the call returns -1, the caller should sleep for 0.1 second and then proceed as if the call was successful. I implemented it and it looks like the code is working now. Will know for sure tomorrow after some testing.

    Oh, and, BTW, I found some more bugs in Sendy. Let me know if you are interested :)
  • Hi @alinetskiy Glad that you nailed down the problem! I just checked and it turns out not to be a bug with Sendy, but an issue with PHP 5.3.18.

    I just launched an Amazon AMI micro instance with Apache/Linux and installed Sendy on it. I had exactly the same issue as you, curl_multi_select always returning -1. The PHP version is 5.3.18.

    I then checked my other Sendy installation on MediaTemple with PHP version 5.3.5, curl_multi_select returns the correct number of threads.

    I searched the web for this issue and found that others were having similar issue with curl_multi_select always returning -1 with PHP 5.3.18:

    http://grokbase.com/t/php/php-bugs/12b12ps1dy/php-bug-bug-63411-new-curl-multi-select-returns-invalid-value
    https://bugs.php.net/bug.php?id=63411
    https://bugs.php.net/bug.php?id=61141
    https://bugs.php.net/bug.php?id=42020

    Yes, let the script sleep for 100 milliseconds when curl_multi_select fails - works. :)

    I've updated the current build on http://sendy.co/get-updated

    Thanks and sorry that you have to discover this. My kudos to you for your unrelentless quest in nailing down the issue. :)
This discussion has been closed.