Cannot reproduce Undefined index: defaultLanguageId

Lukas W.

Well-known member
Affected version
2.0.0 RC 1
I have a bunch of these in my error log:

Code:
ErrorException: [E_NOTICE] Undefined index: defaultLanguageId src/XF/App.php:945
Generated by: Unknown account Nov 7, 2017 at 9:33 PM
Stack trace
#0 src/XF/App.php(945): XF::handlePhpError(8, '[E_NOTICE] Unde...', '<censored>', 945, Array)
#1 src/XF/Container.php(228): XF\App->XF\{closure}(0, Array, Object(XF\Container))
#2 src/XF/App.php(2260): XF\Container->create('language', 0)
#3 src/XF.php(411): XF\App->language(0)
#4 src/XF.php(432): XF::language()
#5 src/XF/Error.php(227): XF::phrase('unexpected_data...', Array)
#6 src/XF/Error.php(210): XF\Error->getPhrasedTextIfPossible('An unexpected d...', 'unexpected_data...')
#7 src/XF/App.php(1868): XF\Error->displayFatalExceptionMessage(Object(XF\Db\Exception))
#8 src/XF.php(146): XF\App->displayFatalExceptionMessage(Object(XF\Db\Exception))
#9 [internal function]: XF::handleException(Object(XF\Db\Exception))
#10 {main}

Here's a bit more info if needed.
 
These lines are interesting:
Code:
#5 src/XF/Error.php(227): XF::phrase('unexpected_data...', Array)
#6 src/XF/Error.php(210): XF\Error->getPhrasedTextIfPossible('An unexpected d...', 'unexpected_data...')
#7 src/XF/App.php(1868): XF\Error->displayFatalExceptionMessage(Object(XF\Db\Exception))
#8 src/XF.php(146): XF\App->displayFatalExceptionMessage(Object(XF\Db\Exception))
#9 [internal function]: XF::handleException(Object(XF\Db\Exception))
Note that it's trying to display a fatal exception message. Specifically, it's trying to to report "An unexpected database error occurred. Please try again later.".

I know it's somewhat related to an add-on but ideally you'd need to try and identify what the database error is. That could be the route cause.
 
Does MySQL keep an error log? If so, where can I find it?

I have a second error message that gives me the feeling that something with the databse is odd.

Code:
XF\Db\Exception: MySQL query error [1615]: Prepared statement needs to be re-prepared src/XF/Db/AbstractStatement.php:212
Generated by: Marit Nov 8, 2017 at 8:01 AM
Stack trace
            -- XFDB=noForceAllWrite
            INSERT INTO xf_session_activity
                (`user_id`, `unique_key`, `ip`, `controller_name`, `controller_action`, `view_state`, `params`, `view_date`, `robot_key`)
            VALUES
                (?, ?, ?, ?, ?, ?, ?, ?, ?)
            ON DUPLICATE KEY UPDATE ip = VALUES(ip),
                controller_name = VALUES(controller_name),
                controller_action = VALUES(controller_action),
                view_state = VALUES(view_state),
                params = VALUES(params),
                view_date = VALUES(view_date),
                robot_key = VALUES(robot_key)
        
------------

#0 src/XF/Db/Mysqli/Statement.php(174): XF\Db\AbstractStatement->getException('MySQL query err...', 1615, 'HY000')
#1 src/XF/Db/Mysqli/Statement.php(69): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1615, 'HY000')
#2 src/XF/Db/AbstractAdapter.php(69): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Repository/SessionActivity.php(152): XF\Db\AbstractAdapter->query('\n\t\t\t-- XFDB=noF...', Array)
#4 src/XF/Pub/Controller/AbstractController.php(65): XF\Repository\SessionActivity->updateSessionActivity(3, '185.134.4.80', 'RPGS\\Pub\\Contro...', 'Index', Array, 'valid', '')
#5 src/XF/Pub/Controller/AbstractController.php(40): XF\Pub\Controller\AbstractController->updateSessionActivity('Index', Object(XF\Mvc\ParameterBag), Object(XF\Mvc\Reply\View))
#6 src/XF/Mvc/Controller.php(270): XF\Pub\Controller\AbstractController->postDispatchType('Index', Object(XF\Mvc\ParameterBag), Object(XF\Mvc\Reply\View))
#7 src/XF/Mvc/Dispatcher.php(271): XF\Mvc\Controller->postDispatch('Index', Object(XF\Mvc\ParameterBag), Object(XF\Mvc\Reply\View))
#8 src/XF/Mvc/Dispatcher.php(87): XF\Mvc\Dispatcher->dispatchClass('RPGS:RPGs', 'Index', 'html', Object(XF\Mvc\ParameterBag), 'rpgs', Object(RPGS\Pub\Controller\RPGs), NULL)
#9 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(1852): XF\Mvc\Dispatcher->run()
#11 src/XF.php(328): XF\App->run()
#12 index.php(13): XF::runApp('XF\\Pub\\App')
#13 {main}
 
I would think that could well be the same error but happening late enough in the code for XF to catch it and present it properly.

Try increasing these values in MySQL:

table_definition_cache
table_open_cache

Could you let us know what the existing values are?
 
Just to be clear, is that 7000 or 7? 7000 is more than sufficient (it usually defaults to 2000).

table_definition_cache defaults to -1 which is "autosize". Apparently it calculates that based on the table_open_cache value:
Code:
400 + (table_open_cache / 2)
But it puts a cap on it of 2000. 400 is the smallest value that accepts. (At least based on the MySQL 5.7 docs).

You could try setting it at -1 to see if that improves anything.
 
sitevalley.com. It's a really old contract, so it only costs me 1.35€/month, but it seems like the limits are showing up now.
Nine times out of ten, you get what you pay for :)

Which is why no-one who wants to host a dynamic application like XenForo should ever touch a host whose name has a common slang for "father" in it or has a name based off of an animal urban legends would have you believe lives in the sewers.


Fillip
 
@Chris_D so while I assume this is not really a bug then, would there be a way to produce a more informative error message that cover such events?

Edit Maybe this thread should be moved to "Troubleshooting and problems"?
 
I'm leaving the bug open at this time because the undefined index defaultLanguageId problem (which was likely caused by the database failure in the first place) masked the real error (the database error). I think we need to address that.
 
Although we could make the defaultLanguageId check safer, it shouldn’t be necessary to.

The getPhrasedTextIfPossible method should catch an undefined index error there.

Which PHP version are you running and did you get closer to finding out what the underlying DB error was?
 
Which PHP version are you running
It was php7.0

did you get closer to finding out what the underlying DB error was?
Unfortunately not. The error log kept being flooded with Prepared statement needs to be re-prepared-errors, but the originally reported undefined index-error hasn't appeared anymore after the first two dozen times that made me file this report. I've already copied my production forum over to my new host - and luckily all those errors seem to be gone -, but if you want to look through the old configuration and installation, I can provide you with all necessary login details, etc. Even though currently inaccessible and no longer in operation, database and files are still existing.
 
Essentially, we don't see how this error would be triggered -- the code that is triggering the error is actually catching all exceptions (and ignoring them). That's how it does the fallback system and how it's working in our tests.

The only thing we can think of is an opcache-related issue. This is something we used to see with some regularity with PHP 5.4 and APC, though it's certainly possible it could still happen in other scenarios with 5.6+ and Opcache. The fact that this presumably disappeared makes me think that this indeed could be related to the code executing slightly differently than as written.
 
opcache seems to be disabled in the php extensions menu.
1NavbHP.png
 
Some sort of opcode caching still seems like a likely culprit here though it would have to be coming from somewhere else, unless it just so happens that opcache is enabled somewhere else which isn't reflected in the interface above.

Either way, this is not something we can reproduce under any circumstance on any PHP version, nor something we would ever expect to happen with the code that's running here.

We'll have to consider this "one of those things" but please do let us know if any of these issues continue.
 
I can confirm this error on XF 2.0.1 with PHP 7.0. Received multiple times.

I use 2 addons - Chat 2 and Content Ratings

  • ErrorException: [E_NOTICE] Undefined index: defaultLanguageId
  • src/XF/App.php:962
  • Generated by: Unknown account
  • Jan 5, 2018 at 10:06 PM
Stack trace
#0 src/XF/App.php(962): XF::handlePhpError(8, '[E_NOTICE] Unde...', '/home/abcd/...', 962, Array)
#1 src/XF/Container.php(228): XF\App->XF\{closure}(0, Array, Object(XF\Container))
#2 src/XF/App.php(2288): XF\Container->create('language', 0)
#3 src/XF.php(411): XF\App->language(0)
#4 src/XF.php(432): XF::language()
#5 src/XF/Error.php(237): XF:: Phrase('unexpected_data...', Array)
#6 src/XF/Error.php(220): XF\Error->getPhrasedTextIfPossible('An unexpected d...', 'unexpected_data...')
#7 src/XF/App.php(1896): XF\Error->displayFatalExceptionMessage(Object(XF\Db\Exception))
#8 src/XF.php(146): XF\App->displayFatalExceptionMessage(Object(XF\Db\Exception))
#9 [internal function]: XF::handleException(Object(XF\Db\Exception))
#10 {main}
Request state
array(4) {
["url"] => string(22) "/index.php?chat/update"
["referrer"] => string(38) "https://www.example.com/members/"
["_GET"] => array(1) {
["chat/update"] => string(0) ""
}
["_POST"] => array(11) {
["channel"] => string(4) "room"
["room_id"] => string(1) "1"
["last_id"] => array(1) {
[1] => string(3) "196"
}
["conv_id"] => string(1) "0"
["conv_only"] => string(1) "0"
["conv_last_active"] => string(10) "1515037082"
["is_chat_page"] => string(5) "false"
["_xfRequestUri"] => string(9) "/members/"
["_xfWithData"] => string(1) "1"
["_xfToken"] => string(8) "********"
["_xfResponseType"] => string(4) "json"
}
}
 
Back
Top Bottom