Page MenuHomePhabricator

"Unable to determine IP" when running phpsh
Closed, ResolvedPublic

Description

vagrant@mediawiki-vagrant:~$ phpsh
Starting php
phpsh failed to initialize PHP.
Fix the problem and hit enter to reload or ctrl-C to quit.

Fatal error: Uncaught exception 'MWException' with message 'Unable to determine IP.' in /vagrant/mediawiki/includes/WebRequest.php on line 1123

MWException: Unable to determine IP. in /vagrant/mediawiki/includes/WebRequest.php on line 1123

Call Stack:
    0.9053   10796800   1. MWExceptionHandler::handleException() /vagrant/mediawiki/includes/exception/MWExceptionHandler.php:0
    0.9053   10796920   2. MWExceptionHandler::rollbackMasterChangesAndLog() /vagrant/mediawiki/includes/exception/MWExceptionHandler.php:169
    0.9053   10796952   3. wfGetLBFactory() /vagrant/mediawiki/includes/exception/MWExceptionHandler.php:138
    0.9082   10871968   4. LBFactory::singleton() /vagrant/mediawiki/includes/GlobalFunctions.php:3227
    0.9102   10910264   5. LBFactorySimple->__construct() /vagrant/mediawiki/includes/db/loadbalancer/LBFactory.php:78
    0.9102   10910384   6. LBFactory->__construct() /vagrant/mediawiki/includes/db/loadbalancer/LBFactorySimple.php:37
    0.9103   10910536   7. LBFactory->newChronologyProtector() /vagrant/mediawiki/includes/db/loadbalancer/LBFactory.php:51
    0.9380   11182576   8. WebRequest->getIP() /vagrant/mediawiki/includes/db/loadbalancer/LBFactory.php:299


Fatal error: Uncaught exception 'MWException' with message 'Unable to determine IP.' in /vagrant/mediawiki/includes/WebRequest.php on line 1123

MWException: Unable to determine IP. in /vagrant/mediawiki/includes/WebRequest.php on line 1123

Call Stack:
    0.9525   11183352   1. MediaWiki\Session\SessionManager->shutdown() /vagrant/mediawiki/includes/session/SessionManager.php:0
    0.9705   11183400   2. MediaWiki\Session\SessionBackend->save() /vagrant/mediawiki/includes/session/SessionManager.php:449
    0.9707   11183400   3. User->getName() /vagrant/mediawiki/includes/session/SessionBackend.php:516
    0.9707   11183448   4. WebRequest->getIP() /vagrant/mediawiki/includes/user/User.php:1951

PHP Fatal error:  Uncaught exception 'MWException' with message 'Unable to determine IP.' in /vagrant/mediawiki/includes/WebRequest.php:1123
Stack trace:
#0 /vagrant/mediawiki/includes/db/loadbalancer/LBFactory.php(299): WebRequest->getIP()
#1 /vagrant/mediawiki/includes/db/loadbalancer/LBFactory.php(51): LBFactory->newChronologyProtector()
#2 /vagrant/mediawiki/includes/db/loadbalancer/LBFactorySimple.php(37): LBFactory->__construct(Array)
#3 /vagrant/mediawiki/includes/db/loadbalancer/LBFactory.php(78): LBFactorySimple->__construct(Array)
#4 /vagrant/mediawiki/includes/GlobalFunctions.php(3227): LBFactory::singleton()
#5 /vagrant/mediawiki/includes/exception/MWExceptionHandler.php(138): wfGetLBFactory()
#6 /vagrant/mediawiki/includes/exception/MWExceptionHandler.php(169): MWExceptionHandler::rollbackMasterChangesAndLog(Object(MWException))
#7 [internal function]: MWExceptionHandler::handleException(Object(MWException))
#8 {main}
  thrown in /vagrant/mediawiki/includes/WebRequest.php on line 1123
PHP Fatal error:  Uncaught exception 'MWException' with message 'Unable to determine IP.' in /vagrant/mediawiki/includes/WebRequest.php:1123
Stack trace:
#0 /vagrant/mediawiki/includes/user/User.php(1951): WebRequest->getIP()
#1 /vagrant/mediawiki/includes/session/SessionBackend.php(516): User->getName()
#2 /vagrant/mediawiki/includes/session/SessionManager.php(449): MediaWiki\Session\SessionBackend->save(true)
#3 [internal function]: MediaWiki\Session\SessionManager->shutdown()
#4 {main}
  thrown in /vagrant/mediawiki/includes/WebRequest.php on line 1123

Event Timeline

Tgr raised the priority of this task from to Needs Triage.
Tgr updated the task description. (Show Details)
Tgr added a project: MediaWiki-Vagrant.
Tgr subscribed.

Workaround: run it with REMOTE_ADDR='127.0.0.1' phpsh. The stack trace seems to be a secondary error while doing error handling, but I get no error when using the workaround so the primary error must be related. hhvmsh is not affected.

I have seen similar errors in the past so not sure if this is caused / made worse by SessionManager or not. The root issue is that $wgCommandLineMode should be set to true when a REPL is called.

Workaround: run it with REMOTE_ADDR='127.0.0.1' phpsh.

Actually not, it will stop phpsh from showing errors but any PHP command will result in subprocess died with return code: 0 PHP died. Restarting php.

This seems non-trivial to solve. Web entry points require a bunch of context that does not make sense for a REPL (such as an URL). The only properly working CLI entry point is apparently doMaintenance, which assumes that there is a maintenance class and the shell should exit after running that. commandLine.inc looks like the right tool for the job (it overrides Maintenance to not do anything apart from setting up the context so that a top-scope script can be run afterwards) but it somehow conflicts with phpsh's I/O handling and freezes up.

The workaround I ended up with is installing PsySH (which I prefer anyway) via composer g require psy/psysh and create a simple wrapper script

<?php
require_once '/home/vagrant/.composer/vendor/psy/psysh/bin/psysh';
require_once __DIR__ . "/commandLine.inc";
eval(\Psy\sh());

and run it with mwscript. It throws a bunch of unimportant warnings but works.

Danny_B renamed this task from MediaWiki-Vagrant: "Unable to determine IP" when running phpsh to "Unable to determine IP" when running phpsh.May 23 2016, 4:09 PM

Change 306487 had a related patch set uploaded (by Mattflaschen):
Use psysh for Zend shell instead of phpsh

https://gerrit.wikimedia.org/r/306487

Change 306487 abandoned by Mattflaschen:
Use psysh for Zend shell instead of phpsh

Reason:
Abandoning. Glad to see psysh got in another way: https://gerrit.wikimedia.org/r/#/c/334217/

https://gerrit.wikimedia.org/r/306487

https://gerrit.wikimedia.org/r/#/c/371723/ will fix this by removing phpsh (making it an alias of psysh).

Mainframe98 assigned this task to Tgr.
Mainframe98 subscribed.

https://gerrit.wikimedia.org/r/c/mediawiki/vagrant/+/371723 was merged, and phpsh now just starts psysh.