Fixed Error: Call to a member function has() on null

Joao Prates

Active member
Affected version
2.2.0
Hi,

I am getting loads of these error entries on my server after upgrading yesterday to XenForo v2.2.0.
I had no errors whatsoever in the previous v2.1 version, but now these errors appear literally by the dozens in just a few minutes time, it's hogging our server.

The upgrade process to 2.2.0 went fine, for both XenForo and for the official add-ons, no errors returned whatsoever.

One of the error log details:

Error: Call to a member function has() on null
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php:589
Generated by: Unknown account
Oct 3, 2020 at 10:12 AM
Stack trace
#0 src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php(336): Swift_Mime_SimpleMimeEntity->getHeaderFieldModel('To')
#1 src/XF/Mail/Mailer.php(274): Swift_Mime_SimpleMessage->getTo()
#2 src/XF/Mail/Queue.php(138): XF\Mail\Mailer->send(Object(Swift_Message), NULL, Array)
#3 src/XF/Job/MailQueue.php(12): XF\Mail\Queue->run(G)
#4 src/XF/Job/Manager.php(258): XF\Job\MailQueue->run(G)
#5 src/XF/Job/Manager.php(200): XF\Job\Manager->runJobInternal(Array, G)
#6 src/XF/Job/Manager.php(84): XF\Job\Manager->runJobEntry(Array, G)
#7 job.php(43): XF\Job\Manager->runQueue(false, 8)
#8 {main}
Request state
array(4) {
["url"] => string(8) "/job.php"
["referrer"] => string(48) "https://ecomove.pt/admin.php?tools/upgrade-check"
["_GET"] => array(0) {
}
["_POST"] => array(0) {
}
}

Note: The referrer string can be anything from an admin page to a user just opening a thread to read it, crazy - I can't understand what is causing this.

Server environment report:

You have the recommended PHP version.
PHP version 7.3.16
MySQL version 10.3.21 (10.3.21-MariaDB)
Server software Apache/2.4.43
PHP memory_limit 128M
PHP post_max_size 100M
PHP upload_max_filesize 100M
PHP max_input_vars 1000
PHP max_execution_time 240
cURL version 7.54.0
cURL SSL version OpenSSL/1.0.2u
OpenSSL version OpenSSL 1.0.2u 20 Dec 2019
Suhosin enabled No
Imagick support No
EXIF support Yes
GZip support Yes
mbstring support Yes
gmp support Yes
ZipArchive support Yes

I have already disabled all non-oficial add-ons, language pack, and custom style, but the errors persist at a quick pace.
Here's the list of what I have installed, all disabled for testing except for the official add-ons:

[Widget] Popular threads and posts 1.1.3 - add-on DISABLED for debug
Daily Statistics 2.0.4 - add-on DISABLED for debug
DL6 - Tag Cloud Widget 1.0.1 - add-on DISABLED for debug
Post Content Find / Replace 2.0.1 - add-on DISABLED for debug
XenForo Media Gallery 2.2.0 - still enabled
XenForo Resource Manager 2.2.0 - still enabled
Português Base - language pack DISABLED for debug
Shades of Gray 2.2 - Style DISABLED for debug

Upon entering the admin control panel I can see these warnings at the top:

1601718074401.png

I know how to check the server errors, but have no clue on how to check for the pending jobs and why they're pending.
The jobs error eventually got away on its own, but the server errors like the one I'm posting here about remain by the dozens per hour.

Based on this thread and on the comment from @Brogan , the only users I can think of that have no email address would be the few deleted users we have from them asking to have their account deleted.
In accordance to the GDPR we deleted the data so yes, we have deleted users with no emails, but why should the system be bothered by those?

I'm open to assist the dev team to find the root cause of this bug in any way you see fit.
Please feel free to contact me on conversations if needed.

Cheers,
-jprates
 
Last edited:
I don't think it's necessarily a user with no email address, though I'm not sure what exactly. It could be a bug in the underlying Swiftmailer library that we use, but it's hard to say. A cursory glance at the file mentioned in the error makes me think this shouldn't be possible, unless something else was broken.

Can you check the file health check in the control panel to confirm whether it reports any issues?
 
Hi Mike, thanks for the feedback.

Checking the file consistency was the first thing I did, it all returns to be fine, 5078 were ok on v2.1 and 5525 are fine now on v2.2.
Do these numbers check with yours?

1601720674573.png
 
Did the Swiftmailer library change from v2.1 to v2.2?
I'm asking because my server was running fine and smoothly with no errors whatsoever on v2.1.
 
Would it be possible for you to dump the contents of the xf_mail_queue table and send them to me via a conversation?

Do me a favor as a test and add this to your src/config.php file temporarily:

Code:
$config['enableMailQueue'] = false;

This will skip the queuing process and send emails directly as needed. Note that this could be a little slower, but I want to see if emails are going out as expected. If so, this should at least prevent the mail queue table issues from causing problems.
 
Table export file sent, please check your conversations.
config file also updated and services restarted, logs cleared, waiting for them to pop up again.

Meanwhile here's an interesting fact I noticed while exporting the table:
Most if not all of the mail queue rows were from a mass mail I sent from Admin > Communication > Email users.

This email was sent to let them know the upgrade process was about to start.
I did wait for all the emails to be generated in the admin panel and checked the email outbox to see they were sent before upgrading.

Why are these emails still in the queue table?
Did they linger on the system and the system is trying to send emails generated with an old (v2.1) format that doesn't work now?

Would deleting all of xf_mail_queue rows solve this issue since it seems to be happening from v2.1 pending emails?
Talk me through what you think should be done.

Oh, and I do appreciate your effort giving support on a saturday within 1/2 hour of a bug report being filed!
 
It does seem likely/plausible that these objects aren't unserializing as expected, potentially due to a change in the underlying library. We'll have to investigate further.

I was going to propose emptying the xf_mail_queue table, though I wanted to get a copy of one of the failing mails first. But that sounds like it may resolve the issue, so if you're ok with that, then it should be fine (and you can likely remove the config.php line afterwards).

In terms of the mail sending process, looking at the code, they should be sent without queuing. The queue would normally only be triggered if there was an error sending the email (which should have a log entry).
 
Ok, truncated the table, and going to remove the config option to enable the queue back, let's see how it goes.
Obviously with the queueing off no errors have been logged thus far, let's hope it keeps that way after turning it back on.

Thanks for the help.
 
Just to confirm: No more errors after truncating the xf_mail_queue table.

Hope this helps others that might face the same issue in the future.

Cheers,
-jprates
 
Last edited:
You can empty the table with the following query:

Code:
DELETE FROM xf_mail_queue;

We have made changes for this in 2.2.1. Notably, we'll need to empty the pending queue when upgrading to 2.2 as the underlying mailer library has had a significant upgrade and the pending objects are no longer usable. (Note that having items in the mail queue for an extended period of time isn't really expected; that tends to point to server issues.) We're also making changes to try to catch these errors so the emails don't get stuck in the queue.
 
You can empty the table with the following query:

Code:
DELETE FROM xf_mail_queue;

We have made changes for this in 2.2.1. Notably, we'll need to empty the pending queue when upgrading to 2.2 as the underlying mailer library has had a significant upgrade and the pending objects are no longer usable. (Note that having items in the mail queue for an extended period of time isn't really expected; that tends to point to server issues.) We're also making changes to try to catch these errors so the emails don't get stuck in the queue.

command not found.

I'm trying by logging in as root.
i use VDS
 
You would need to connect to MySQL first (using your username and password) and selecting the XF database.
 
Back
Top Bottom