New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The knex version we're using has a known bug that prevents testing connections #2600
Comments
@pragone Good catch, I had noticed the connection timeouts and my cluster killing them myself but hadn't looked deeper. I think we should test updating to the current recommended version (Separate PR) but in the short term I think you are right on bringing in the recommended changes. Once you get the PR up feel free to ping me as I would be interested in helping test it. |
Well... I'm not so sure now that the solve is so simple. Turns out that while the knex code that initialises the connection pool does not change between 0.13.0 (the version we're using) and 0.14.0 (the version for which the bug was raised), the version of generic-pool does change:
Turns out that in 2.4.2 there's no From a bit more reading they say that knex fixed quite a few connection pool related issues after 0.14.3 (which is when they switched away from generic-pool to tarn). |
@pragone I remember there being some possible breaking changes between versions outside of what you already mentioned. I think I dropped some links to @lauriejim in slack but I should probably read more into it myself |
Perhaps... But TBH, this is becoming a blocker for me. Having a dependable connection pooling mechanism is a hygiene factor of any production-ready system. |
BTW... thanks @derrickmehaffy for the responsiveness 👍 |
No problem @pragone this directly affects me as well. If you want to give it a shot and update here on your testing I'll start playing around as well. Your skills are probably a bit better than mine but I do agree on the production ready system. There are a few other things that the bookshelf side of Strapi needs to have done for it to be considered "Production ready" mainly getting bookshelf at least up to the current level of mongoose in terms of usability. |
A few key things I see in that changelog that also will directly affect #2562
There is also quite a few other misc bug fixes in latest versions I think would benefit Strapi going forward, so we should focus on making sure nothing breaks while updating to newer versions. Doing so will make the job easier I referenced in my previous comment |
Hi @derrickmehaffy. I've submitted a PR with the change in question. Would love some help on defining a testing process for this. I re-read the changelos, and these are all the breaking changes in Knex for the upgrade we're doing here (from 0.13.0 to 0.16.2): 0.16.1
0.15.0
0.14.0
|
Ok... having said all that, the questions are: |
BTW... on your other comment. It would be nice to have the query aggregation support of mongoose in bookshelf as well... But at least, with the help I got in stackoverflow I was able to do the aggregation queries myself so no biggie... I would say that this functionality is desirable, but not required for being prod-ready. Again, my 2 cents :) |
@pragone So the travisCI tests implemented on the monorepo don't actually test core functionality (working on that with cypress but honestly that is more geared towards adminUI testing) I believe all the current tests are done on mongo anyway. @lauriejim generally tests each DB manually before release. Obviously in the future we want each possible DB type to be tested automatically but that is WIP. Also in the great words of Captain Jack Sparrow Tests are "more like guidelines" than actual results 😉 It would only be considered a breaking change if you were to update an existing application and it would not start without modifications (core changes required to start the server) in this case I don't think so as you actually have default values assigned if there are none in the config. Realistically what we should do is test on both platforms Postgres/MySQL with different database versions (recommended and above) so we don't get any surprises after the PR is merged and is live. And yes it may not be required for production (aggregation support) but with the end goal being: Strapi is frontend and backend agnostic, we should strive to have the same functionality no matter the backend database as much as possible. This also includes the small things like unique constraint keys, ect. But a bit out of the scope of this specific issue. With the addition of SQLite support (via @pierreburgy 's PR ) we will also have another bookshelf related database to test in the future as well which will be important to allow people to test easily. Among this change and my purposed one on merging the templates for mongoose/bookshelf to allow users to flip flop between either side without having to regenerate their models we are pushing closer to the goal of being both frontend and backend agnostic 😄 TLDR: We are getting there, we just need more people like you to just jump in the deep end and find the small things to work on. |
Informations
What is the current behavior?
Strapi uses an old version of knex with a known issue.
Specifically the issue I'm experiencing is that after connections to the DB have been idle for quite a while, they may be disconnected, but because of knex/knex#2321 (which I've checked the code and the issue is also affecting knex 0.13.0 which is the version we're using), the connection is not actually being tested before it is used.
The comment that shows the actual key of the issue in knex is knex/knex#2321 (comment) and it also suggests the fix: to pass
testOnBorrow: true
as a config to the pool.Now, because the connection pool options are not very configurable (which is called out in #2030) we need to change the code in the knex hook to be able to fix it.
Considering that the fix in knex was to set this option as true by default I'd suggest we do the same.
(Alternatively we could upgrade knex, but the later versions use a different connection pool library
tarn
instead ofgeneric-pool
and that may be a breaking change.Steps to reproduce the problem
Bring app up that uses a mysql connection.
Let it sleep for a few hours or kill the connection somehow else
Make a request that need the DB
It has an error and does not recover
What is the expected behavior?
It should reconnect to the DB and fulfil the request
Suggested solutions
I'll submit a PR, but I believe it should be as simple as setting
testOnBorrow: true
as default on the knex options. Also, TBH, there's no good reason why the pool options are not being set and are configurable wherever we use knex. So I'll include some of that in the PR.The text was updated successfully, but these errors were encountered: