Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upexpirationChecker won't recreate connection object with Postgres client #3578
Comments
|
So, after a couple of digging, I think I was able to find the issue and at least provide some kind of solution, even if a naive one. The connectionConfigExpirationChecker property is not being used except for the first time. That is happening because it's only being called on the first create call on From what I've investigated, Basically, I've just added a setTimeout on the I've done some local tests here with the codebase I'm working with and I finally had the behaviour I was expecting without any side-effects from what I can see. @kibertoad , @oranoran , @Ali-Dalal - maybe you could give some insight in this since you guys were involved in the last PR related to this functionality. |
|
I actually don't like or understand why there even is Then it would be up to client code to implement logic when it wants to get fresh config and when it wants to for example return the same already resolved promise for the old config. Could someone explain me better how that async / function getting of connection parameters works nowadays or what am I missing here? |
|
@elhigu I believe that this I can't tell for every case but at least in my case, this property I believe that the async |
|
@dsbrgg is your expectation for the configuration to expire at the timeout, or for actual living connections that were created using it to expire? |
That would be as easy or even easier if knex would just always reload config if it is changed. Then there would be no need for that kind of timer. So to me that parameter still looks like a hack to me instead of feature. I remember that async knex configuration feature first implementation was not very versatile for many use cases either (IIRC it only made possible to get async config once and then there was no way to update it afterwards)... |
|
@Ali-Dalal Yes, like I said, the async config works fine. My problem has been with the @oranoran I suppose both. Since the connection would have to expire after a timeout, the resource would have to be recreated or you would end up with an invalid knex instance - which is my case, after the timeout, I get invalid credentials errors. Regardless, the @elhigu I'm sorry but I don't understand what you mean by "reloading the config if it's changed". The timer was just a naive approach to the matter as I was under the impression that it was supposed to verify if the connection was valid from time to time or before requests were made and then call the async |
I mean something like this:
That would cause knex to reload every 5 seconds, since returned configuration object is changing every 5 seconds (of course connection callback could also return a promise which would be asynchronously resolved).
I'm pretty sure that it does not check if the connection details are valid, but only re-reads new config with that interval. |
|
@elhigu Thanks for the example. I guess this could do it.
I think this is not actually happening. At least from what I've tested, even after the expiration was passed, That's what I mean when I say that the connection is valid or not, since the expiration, for me, means that at that point that the connection would no longer be valid. It is called once when the connection is first being created and never again to see if the Anyway, I'll try something around that example you've showed. |
I don't think that my example will work at all, since it is an imaginary API how I would have wanted that configuration reloading feature to work. |
|
Oh sorry, I thought you meant as if that could solve it. Could this function be called upon the validation of a connection? This way the connection could be destroyed and also the connection would be rebuilt at that point. This way it would prevent any type of timer. I suppose the property |
|
Maybe... more people should read through those connection parts of the code base to make sure that it is a valid solution... I don't know when I would have time to concentrate on that. |
|
I don't need this immediately as I came up with this issue for an upcoming feature on my project but it would be great if this could be implemented. Thanks for the responses as well @elhigu! |
Environment
Knex version: 0.20.3
Database + version: psql (PostgreSQL) 12.1
OS: macOS 10.14.6
Bug
The
expirationCheckerproperty on the connection object is not being called to recreate the connection object with new credentials for the database, even though the timeout was reached.The first time that a request is being made, it works fine but after the timeout, it won't allow to make subsequent connections to the database returning a
permission_deninederror (as it should). Here's an example of the knex instance being made.It came to my attention that the psql config interface does not have an
expirationCheckerproperty in it but, I'm not sure if this has a direct impact with this situation since the function that would update the connection seems to be called on the first time.