Skip to content
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

Error reinitializing connection pool #866

Open
blah238 opened this issue Jun 12, 2015 · 1 comment
Open

Error reinitializing connection pool #866

blah238 opened this issue Jun 12, 2015 · 1 comment

Comments

@blah238
Copy link
Contributor

blah238 commented Jun 12, 2015

It was mentioned here that since 0.8.x it should be possible to call knex.initialize() after knex.destroy() to re-initialize a connection pool.

However, I am getting the error below:

Object [object KnexClient] has no method 'initialize'
at Function.initialize (./node_modules/knex/lib/util/make-knex.js:44:21)

Using knex@0.8.6 and sqlite3@3.0.8.

I have created a Gist demonstrating the issue.

It seems that here the make-knex utility attempts to call a non-existent initialize function on the client object. Is this functionality just not implemented yet, or was I misunderstanding the intention?

I could work around this by creating a new Knex instance (and remembering to replace every reference to the previous instance, which is not always straightforward given things like module caching and 3rd party code), but it would simplify things greatly by being able to reuse the same instance and just reinitializing its connection pool.

@blah238 blah238 changed the title Error reinitialzing connection pool Error reinitializing connection pool Jun 12, 2015
@thedevkit
Copy link

I was having the same issue and my resolution was to call knex.client.initializePool (had to dig through the code to find this).

I agree with your statement - having to create a new Knex instance is very difficult and probably a bad practice because you're messing with the module caching.

My main concern at this point - if the same instance is being used in separate invocations (due to module caching) and I use knex.destroy to teardown the pool, is it possible that between calling knex.client.initializePool and executing the query, the connection pool can be destroyed by a different invocation?

This seems like a very dangerous possibility. Ideally there should be a way to use a "stateless" knex instance. My environment is intended to be completely stateless, so having a knex instance where the connection pool is maintained throughout the process (my process does not necessarily exit between requests) is a liability.

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

No branches or pull requests

2 participants