• Resolved websmyth

    (@websmyth)


    Hi,

    We’ve been troubleshooting an issue with bbPress email notifications for a while now and think we may have narrowed it down to this plugin. Our forum is setup to notify all users (around 600-700 in total) of all new posts and replies on the forum and we use Mailgun to handle email delivery.

    When users submit a new topic/reply we’re experiencing a 502 error and the page times out. As a result, not all emails are being sent. Having spoken to WPEngine at length about what is causing this (no error log messages are being received), they’ve responded as below:

    I understand you are experiencing issues with making new forum posts and replies without receiving a 502 error. I also understand you are utilizing the bbpress-notify-nospam plugin which sends an email to every user upon new posts and replies attempting to send emails to about 700+ users within a single function.

    The issue is related to the emails attempting to be routed through SMTP in one single function. The plugin function that handles the process of sending the emails upon new posts and replies is attempting to route all 700+ emails via SMTP all at once while pulling information from the database before each email is sent. This in return is resulting in our server killing the process as it’s taking too long to complete. Our server will kill any processes that run over 60 seconds to avoid any performance issues on the server, and unfortunately, this limit cannot be modified at this time.

    I am not too familiar with the process that this plugin utilizes to pull the information for each user and send an email to them, but it appears this process needs to be broken apart a bit once you are over a set amount of users, such as attempting to send the emails in multiple batches over a certain amount of time. If you have not already, I would strongly recommend reaching out to the plugin developer to investigate this further.

    Any help would be greatly appreciated!

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author useStrict

    (@usestrict)

    Hi Websmyth,

    You can get around this problem by selecting the ‘Send emails in the background…’ options for both topics and replies. You’ll find it under Settings > Forums > Email Notifications.

    Let me know if that doesn’t fix the issue.

    Cheers,
    Vinny

    Thread Starter websmyth

    (@websmyth)

    Hi Vinny,

    Thanks for such a quick response. That seems to have avoided the error – hopefully everyone will receive their emails now, too!

    Dave

    Thread Starter websmyth

    (@websmyth)

    Apologies for resurrecting this thread, but an update on this…

    Checking the ‘Sending emails in the background…’ option seemed to resolve our 502 issue but unfortunately that doesn’t seem to have resolved our main issue of some users not receiving notifications.

    So our current situation is that around 95% of users receive their notifications, but a couple of users (always the same ones) never do. Using the WP Mail Log plugin, we can see that the emails aren’t being sent/scheduled to these users so it’s not a spam or Mailgun issue.

    The users in question have the same role as the other users that are successfully receiving their emails…very odd. Any ideas as to what could be causing this?

    Thanks again,

    Dave

    Plugin Author useStrict

    (@usestrict)

    Hi Dave,

    Sorry for the delay. I totally missed this. I’d recommend adding some debugging to the part where wp_mail() is called, making it save the current address as well as the full list. That way you can compare them and certify that the loop is completing.

    Put this code in your functions.php and look for the mailout.log file in the same directory. Remove it once you’re satisfied with the results.

    
    function my_show_all_recipients( $recipients )
    {
    	$list = array();
    	foreach ($recipients as $recipient)
    	{
    		$list[$recipient->ID] = $recipient->user_email;
    	}
    	
    	$out = array( 'num_recipients' => count($recipients), 'recipients' => $list );
    	
    	error_log( 'Full recipient list is: ' . print_r($out,1), 3, dirname(__FILE__) . '/mailout.log');
    	
    	return $recipients;
    }
    add_filter( 'bbpnns_filter_recipients_before_send', 'my_show_all_recipients', PHP_INT_MAX, 1 );
    
    function my_debug_mailout_loop( $user_info, $filtered_subject, $filtered_body, $recipient_headers )
    {
    	error_log( 'Sending message to: ' . print_r($user_info->user_email,1), 3, dirname(__FILE__) . '/mailout.log');
    }
    add_action( 'bbpnns_before_wp_mail', 'my_debug_mailout_loop', 10, 4 );
    
    Thread Starter websmyth

    (@websmyth)

    Hi Vinny,

    Thanks for this. I added that code to functions.php and ran a test post. The result in the log file contained 14 copies of:

    Full recipient list is: Array
    (
        [num_recipients] => 0
        [recipients] => Array
            (
            )
    
    )

    I’m guessing that’s not right?

    Plugin Author useStrict

    (@usestrict)

    Indeed it isn’t. Try changing PHP_INT_MAX for -10. I want to know if something is removing the recipients.

    Thread Starter websmyth

    (@websmyth)

    Hmmm, it seems to be producing the same response…

    Thread Starter websmyth

    (@websmyth)

    Hi Vinny,

    Just following up in case this went missing! I left this running and we’re still seeing the same results in the log file… Any ideas?

    Thanks,

    Dave

    Plugin Author useStrict

    (@usestrict)

    Hi Dave,

    I did miss your previous message! Sorry about that!

    The debugging shows that the recipient list is empty. The way it is, nobody gets sent any messages, which doesn’t make sense as you say only a couple of people aren’t getting them.

    Please create an admin account for me using email vinny [at] usestrict [dot] net on a staging server, so I can have a look.

    Cheers,
    Vinny

    Thread Starter websmyth

    (@websmyth)

    Hi Vinny,

    That’s great, thanks! I’ve set up an account from our staging server, so you should have received an email about that now. ??

    Let me know if that doesn’t come through.

    Thanks again,

    Dave

    Plugin Author useStrict

    (@usestrict)

    Nothing yet. Not in the spam folders, either.

    Thread Starter websmyth

    (@websmyth)

    Hi Vinny,

    Thanks for letting me know. I’ve just emailed you directly…

    Dave

    Plugin Author useStrict

    (@usestrict)

    For the record, Dave and I worked on this and it looks like his host is killing the process as he’s got a LOT of users to notify. To make matters worse, the host doesn’t offer pcntl_fork.

    I’m studying the possibility of creating a batch mailer premium add-on to work with Mailgun and Sendgrid, for starters. I don’t want to bloat bbpnns with code that not everyone will need/use.

    I’ll update the thread once I have something more concrete.

    Thread Starter websmyth

    (@websmyth)

    Vinny’s gone above and beyond what I’d expect from a plugin author – thanks so much!

    Plugin Author useStrict

    (@usestrict)

    Thanks for the kind words!

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘502 on new topic/reply submission’ is closed to new replies.