Skip to content
This repository has been archived by the owner on Aug 25, 2019. It is now read-only.

mysqli error in log when try to set up docker container with "external" db #63

Closed
ghost opened this issue Dec 13, 2016 · 3 comments
Closed

Comments

@ghost
Copy link

ghost commented Dec 13, 2016

Hi,

(DAU question incoming, I'm new to docker)

I have a mysql db running on docker (name: mysql). When I try to start the phabricator container with:
docker run \ --rm -p 80:80 -p 443:443 -p 3306:3306 \ --env PHABRICATOR_HOST=localhost \ --env MYSQL_HOST=mysql \ --env MYSQL_USER=phabricator \ --env MYSQL_PASS=secretpassword \ --link mysql:mysql \ --env PHABRICATOR_REPOSITORY_PATH=/repos \ -v /host/repo/path:/repos \ hachque/phabricator

I receive the following error:

[2016-12-13 11:40:23] ERROR 2: mysqli::set_charset(): invalid object or resource mysqli
at [/srv/phabricator/libphutil/src/aphront/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php:81]
arcanist(head=master, ref.master=fad85844314b), phabricator(head=master, ref.master=776a1f3aec35), phutil(head=master, ref.master=5ac2ca121489)
#0 mysqli::set_charset(string) called at [/src/aphront/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php:81]
#1 AphrontMySQLiDatabaseConnection::connect() called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:101]
#2 AphrontBaseMySQLDatabaseConnection::establishConnection() called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:124]
#3 AphrontBaseMySQLDatabaseConnection::requireConnection() called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:31]
#4 AphrontBaseMySQLDatabaseConnection::openConnection() called at [/src/infrastructure/cluster/PhabricatorDatabaseRef.php:456]
#5 PhabricatorDatabaseRef::isReachable(AphrontMySQLiDatabaseConnection) called at [/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php:85]
#6 PhabricatorLiskDAO::newClusterConnection(string, string, string) called at [/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php:66]
#7 PhabricatorLiskDAO::establishLiveConnection(string) called at [/src/infrastructure/storage/lisk/LiskDAO.php:1008]
#8 LiskDAO::establishConnection(string) called at [/src/infrastructure/storage/lisk/LiskDAO.php:516]
#9 LiskDAO::loadRawDataWhere(string, string)
#10 call_user_func_array(array, array) called at [/src/infrastructure/storage/lisk/LiskDAO.php:476]
#11 LiskDAO::loadAllWhere(string, string) called at [/src/infrastructure/env/PhabricatorConfigDatabaseSource.php:19]
#12 PhabricatorConfigDatabaseSource::loadConfig(string) called at [/src/infrastructure/env/PhabricatorConfigDatabaseSource.php:7]
#13 PhabricatorConfigDatabaseSource::__construct(string) called at [/src/infrastructure/env/PhabricatorEnv.php:249]
#14 PhabricatorEnv::buildConfigurationSourceStack(boolean) called at [/src/infrastructure/env/PhabricatorEnv.php:95]
#15 PhabricatorEnv::initializeCommonEnvironment(boolean) called at [/src/infrastructure/env/PhabricatorEnv.php:75]
#16 PhabricatorEnv::initializeScriptEnvironment(boolean) called at [/scripts/init/lib.php:22]
#17 init_phabricator_script(array) called at [/scripts/init/init-setup.php:12]
#18 require_once(string) called at [/scripts/setup/manage_config.php:5]
[2016-12-13 11:40:23] ERROR 2: mysqli::escape_string(): invalid object or resource mysqli
at [/srv/phabricator/libphutil/src/aphront/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php:15]
arcanist(head=master, ref.master=fad85844314b), phabricator(head=master, ref.master=776a1f3aec35), phutil(head=master, ref.master=5ac2ca121489)
#0 mysqli::escape_string(string) called at [/src/aphront/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php:15]
#1 AphrontMySQLiDatabaseConnection::escapeBinaryString(string) called at [/src/aphront/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php:11]
#2 AphrontMySQLiDatabaseConnection::escapeUTF8String(string) called at [/src/xsprintf/qsprintf.php:178]
#3 xsprintf_query(AphrontMySQLiDatabaseConnection, string, integer, string, integer) called at [/src/xsprintf/xsprintf.php:70]
#4 xsprintf(string, AphrontMySQLiDatabaseConnection, array) called at [/src/xsprintf/qsprintf.php:64]
#5 qsprintf(AphrontMySQLiDatabaseConnection, string, string, string, string)
#6 call_user_func_array(string, array) called at [/src/xsprintf/queryfx.php:5]
#7 queryfx(AphrontMySQLiDatabaseConnection, string, string, string, string)
#8 call_user_func_array(string, array) called at [/src/xsprintf/queryfx.php:13]
#9 queryfx_all(AphrontMySQLiDatabaseConnection, string, string, string, string)
#10 call_user_func_array(string, array) called at [/src/aphront/storage/connection/AphrontDatabaseConnection.php:52]
#11 AphrontDatabaseConnection::queryData(string, string, string, string)
#12 call_user_func_array(array, array) called at [/src/infrastructure/storage/lisk/LiskDAO.php:535]
#13 LiskDAO::loadRawDataWhere(string, string)
#14 call_user_func_array(array, array) called at [/src/infrastructure/storage/lisk/LiskDAO.php:476]
#15 LiskDAO::loadAllWhere(string, string) called at [/src/infrastructure/env/PhabricatorConfigDatabaseSource.php:19]
#16 PhabricatorConfigDatabaseSource::loadConfig(string) called at [/src/infrastructure/env/PhabricatorConfigDatabaseSource.php:7]
#17 PhabricatorConfigDatabaseSource::__construct(string) called at [/src/infrastructure/env/PhabricatorEnv.php:249]
#18 PhabricatorEnv::buildConfigurationSourceStack(boolean) called at [/src/infrastructure/env/PhabricatorEnv.php:95]
#19 PhabricatorEnv::initializeCommonEnvironment(boolean) called at [/src/infrastructure/env/PhabricatorEnv.php:75]
#20 PhabricatorEnv::initializeScriptEnvironment(boolean) called at [/scripts/init/lib.php:22]
#21 init_phabricator_script(array) called at [/scripts/init/init-setup.php:12]
#22 require_once(string) called at [/scripts/setup/manage_config.php:5]
[2016-12-13 11:40:23] EXCEPTION: (AphrontQueryException) #0: at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:355]
arcanist(head=master, ref.master=fad85844314b), phabricator(head=master, ref.master=776a1f3aec35), phutil(head=master, ref.master=5ac2ca121489)
#0 AphrontBaseMySQLDatabaseConnection::throwQueryCodeException(integer, string) called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:289]
#1 AphrontBaseMySQLDatabaseConnection::throwQueryException(mysqli) called at [/src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php:185]
#2 AphrontBaseMySQLDatabaseConnection::executeRawQuery(string) called at [/src/xsprintf/queryfx.php:8]
#3 queryfx(AphrontMySQLiDatabaseConnection, string, string, string, string)
#4 call_user_func_array(string, array) called at [/src/xsprintf/queryfx.php:13]
#5 queryfx_all(AphrontMySQLiDatabaseConnection, string, string, string, string)
#6 call_user_func_array(string, array) called at [/src/aphront/storage/connection/AphrontDatabaseConnection.php:52]
#7 AphrontDatabaseConnection::queryData(string, string, string, string)
#8 call_user_func_array(array, array) called at [/src/infrastructure/storage/lisk/LiskDAO.php:535]
#9 LiskDAO::loadRawDataWhere(string, string)
#10 call_user_func_array(array, array) called at [/src/infrastructure/storage/lisk/LiskDAO.php:476]
#11 LiskDAO::loadAllWhere(string, string) called at [/src/infrastructure/env/PhabricatorConfigDatabaseSource.php:19]
#12 PhabricatorConfigDatabaseSource::loadConfig(string) called at [/src/infrastructure/env/PhabricatorConfigDatabaseSource.php:7]
#13 PhabricatorConfigDatabaseSource::__construct(string) called at [/src/infrastructure/env/PhabricatorEnv.php:249]
#14 PhabricatorEnv::buildConfigurationSourceStack(boolean) called at [/src/infrastructure/env/PhabricatorEnv.php:95]
#15 PhabricatorEnv::initializeCommonEnvironment(boolean) called at [/src/infrastructure/env/PhabricatorEnv.php:75]
#16 PhabricatorEnv::initializeScriptEnvironment(boolean) called at [/scripts/init/lib.php:22]
#17 init_phabricator_script(array) called at [/scripts/init/init-setup.php:12]
#18 require_once(string) called at [/scripts/setup/manage_config.php:5]
[ FAILED ] /etc/init.simple/10-boot-conf

@hach-que
Copy link
Contributor

My initial guess is that this has something to do with the MySQL instance you are connecting to.

The stack trace looks like a bug in upstream code. This Docker container doesn't change how Phabricator itself connects to MySQL, we just configure it based on environment variables. The docker run command looks fine to me.

Note that when you report this issue upstream to Phabricator, they'll likely want you to go through their tediously long and complicated setup process which you can find here: https://secure.phabricator.com/book/phabricator/article/installation_guide/.

You should try to replicate the environment as close as possible, including getting the Phabricator you set up manually to connect to the same MySQL instance that you are trying to connect this container to.

Once you can replicate it on the upstream guide, you can report the issue here: https://secure.phabricator.com/maniphest/task/edit/form/3/

Outside of that, my suggestion would be to try using the mysql image that our Docker compose file uses, as that is known to work.

@michalciolek
Copy link

I have the same. To fix this, you can:

  1. Set up mysql container to expose the ports on the outside:
    docker run -p 93306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
    and set phabricator container to use it:
docker run --rm -p 80:80 -p 443:443 --env PHABRICATOR_HOST=localhost --env MYSQL_HOST=localhost --env MYSQL_USER=root --env MYSQL_PASS=my-secret-pw --env MYSQL_PORT=93306 --env PHABRICATOR_REPOSITORY_PATH=/repos  -v /host/repo/path:/repos \ hachque/phabricator

or
2) use docker-compose with https://github.com/hach-que-docker/phabricator/blob/master/DOCKER-COMPOSE.md - it work for me.

@hach-que
Copy link
Contributor

I just ran into this during testing. It's because --link mysql causes MYSQL_PORT to be set to something silly like tcp://...:3306/, because of the link name.

We expect MYSQL_PORT to either empty or to have an integer (like 3306) in it. I'm going to add a startup check to make this failure more clear as to the issue it causes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants