cobyism / ghost-on-heroku

One-button Heroku deploy for the Ghost blogging platform.
MIT License
743 stars 686 forks source link

Timeout acquiring a connection #150

Closed mechanical-turk closed 6 years ago

mechanical-turk commented 6 years ago

We just saw this error today. Any ideas how to approach this issue? We are thinking about increasing the max pool size from 5 to 7-8. Not sure if it will resolve the issue though. Has anyone seen this error before?

[31mMESSAGE: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
2018-07-24T00:39:28.212877+00:00 app[web.1]: 
2018-07-24T00:39:28.212878+00:00 app[web.1]: TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
2018-07-24T00:39:28.212880+00:00 app[web.1]:     at /app/node_modules/knex/lib/client.js:340:13
2018-07-24T00:39:28.212882+00:00 app[web.1]:     at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
2018-07-24T00:39:28.212884+00:00 app[web.1]:     at /app/node_modules/bluebird/js/release/catch_filter.js:17:41
2018-07-24T00:39:28.212886+00:00 app[web.1]:     at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
2018-07-24T00:39:28.212888+00:00 app[web.1]:     at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:512:31)
2018-07-24T00:39:28.212890+00:00 app[web.1]:     at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:569:18)
2018-07-24T00:39:28.212891+00:00 app[web.1]:     at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:614:10)
2018-07-24T00:39:28.212893+00:00 app[web.1]:     at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:689:18)
2018-07-24T00:39:28.212894+00:00 app[web.1]:     at Async._drainQueue (/app/node_modules/bluebird/js/release/async.js:133:16)
2018-07-24T00:39:28.212896+00:00 app[web.1]:     at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:143:10)
2018-07-24T00:39:28.212897+00:00 app[web.1]:     at Immediate.Async.drainQueues (/app/node_modules/bluebird/js/release/async.js:17:14)
2018-07-24T00:39:28.212899+00:00 app[web.1]:     at runCallback (timers.js:672:20)
2018-07-24T00:39:28.212900+00:00 app[web.1]:     at tryOnImmediate (timers.js:645:5)
2018-07-24T00:39:28.212902+00:00 app[web.1]:     at processImmediate [as _immediateCallback] (timers.js:617:5)
mars commented 6 years ago

When is this error occurring? During release or in runtime? Is there substantial traffic on the app when this occurs?

If you're explicitly using transactions, as the error suggests, please verify that the program code is not leaking connections.

It's definitely the case that Ghost on Heroku is preset for deployment with that minimal free database which only supports ten connections.

Raising that max config might help or overload the DB's connection limit, and then upgrading the database will be the next step to support more connections.

mechanical-turk commented 6 years ago

Hi @mars ! We love the create-react-app buildpack :)

To answer your questions:

1) The error occurs during runtime. 2) We had a blog post that went semi-viral yesterday. However, the server kept up with the request for the most part. It crashed during a calmer time, which is curious. 3) We are using the free tier JAWSDB, so that could be the source of the issue as well. 4) We haven't modified any of the application's business logic. We just wrote a little bit of css. Therefore if this issue is caused by some transaction issue, it is likely that it comes from the main source code. (just fyi)

We'll raise the connection limit to a 10 for now, just to be on the safer side. If it persists, we'll upgrade our db plan.

mars commented 6 years ago

Sounds good! Note that the connection pool max is per-dyno. Therefore, if the app is scaled-up beyond a single dyno (recommended for production), or if it's using preboot which doubles the number of dynos during a deployment, then the connection count may easily surpass the database's limit. That's why I have it preset to half the database limit by default.