mozilla/fxa-auth-db-mysql

./bin/server.js fails to reach remote mysql database

Closed this issue · 6 comments

npm start execution fails inside a docker container.
I use the following commit:

poiuy@debian:~/repositories/github.com/mozilla/fxa-auth-db-mysql$ git lg -1
* afc376c - (HEAD -> master, origin/master, origin/HEAD) (2 days ago) <John Morrison>
| fix(restify): set keepAliveTimeout correctly on api.server object (#381)

I have just modified the name of the builder docker image:

poiuy@debian:~/repositories/github.com/mozilla/fxa-auth-db-mysql$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   Dockerfile-test

no changes added to commit (use "git add" and/or "git commit -a")
poiuy@debian:~/repositories/github.com/mozilla/fxa-auth-db-mysql$ git diff
diff --git a/Dockerfile-test b/Dockerfile-test
index 15b3890..7da3663 100644
--- a/Dockerfile-test
+++ b/Dockerfile-test
@@ -1,2 +1,2 @@
-FROM fxa-auth-db-mysql:build
+FROM fxa-auth-db-mysql:build-latest
 RUN npm install

I built the builder and test docker images using the following commands:

poiuy@debian:~/repositories/github.com/mozilla/fxa-auth-db-mysql$ docker build -t fxa-auth-db-mysql:build-latest -f Dockerfile-build .

poiuy@debian:~/repositories/github.com/mozilla/fxa-auth-db-mysql$ docker build -t fxa-auth-db-mysql:latest -f Dockerfile-test .

I ran the container with this command:

poiuy@debian:~/repositories/github.com/mozilla/fxa-auth-db-mysql$ docker run -it --rm --env "LOG_LEVEL=trace" --env "MYSQL_HOST=172.17.0.5" --env "MYSQL_PASSWORD=test" -v /home/poiuy/repositories/github.com/mozilla/fxa-auth-db-mysql/config/config.js:/app/config/config.js --name fxa-auth-db-mysql-latest fxa-auth-db-mysql:latest npm start

npm start fails with the following stack trace:

> fxa-auth-db-mysql@1.117.0 start /app
> node ./bin/db_patcher.js >/dev/null && node ./bin/server.js

{"Timestamp":1534127639892000000,"Logger":"fxa-auth-db-server","Type":"bin.server.sentryDisabled","Severity":6,"Pid":29,"EnvVersion":"2.0"}
{"Timestamp":1534127639938000000,"Logger":"fxa-auth-db-server","Type":"bin.server.MySql.retryable","Severity":2,"Pid":29,"EnvVersion":"2.0","Fields":{"err":"Error: connect ECONNREFUSED 127.0.0.1:3306"}}
Unhandled rejection Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object._errnoException (util.js:992:11)
    at _exceptionWithHostPort (util.js:1014:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
    --------------------
    at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:130:18)
    at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
    at PoolCluster._getConnection (/app/node_modules/mysql/lib/PoolCluster.js:229:13)
    at PoolNamespace.getConnection (/app/node_modules/mysql/lib/PoolNamespace.js:40:11)
    at PoolCluster.getConnection (/app/node_modules/mysql/lib/PoolCluster.js:145:13)
    at PoolCluster.tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at MySql.ret [as getClusterConnection] (eval at makeNodePromisifiedEval (/app/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:14:23)
    at failure (/app/lib/db/mysql.js:1215:14)
    at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:689:18)
    at Async._drainQueue (/app/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

As you can see, the ./bin/db_patcher.js script can reach the database server, but i can't see how to change my configuration to force ./bin/server.js to connect to ip 172.17.0.5, which is my mysql database server ip. It does not seem to care about MYSQL_HOST environment variable as opposed to ./bin/dp_patcher.js.

Am I doing something wrong ?

@nicolasmeric, I think there is one more environment variable you need to set. Does it work if you also add --env "MYSQL_SLAVE_HOST=172.17.0.5" to your docker run command?

Thanks!
Indeed, it seems that the slave configuration is mandatory. I had to set MYSQL_SLAVE_HOST and MYSQL_SLAVE_PASSWORD.
So, must i assume that using just a single mysql database server is impossible with fxa-auth-db-mysql ?
It would be quite inconvenient.

No, it's fine for them both to point at the same MySQL instance, that is e.g. how we have it set up in local dev.

It seems a bit weird to me. Will the data remain consistent if fxa-auth-db-mysql enable two instances and use the same database ?

Yep, we ensure consistency at the db level using transactions in our stored procedures as necessary. And a single-db setup is pretty well-tested for us at this point.

OK, thank you for your answers. I close.