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

When should I use Pool.end(); #1670

Closed
danilloalvis opened this issue Jun 9, 2018 · 2 comments
Closed

When should I use Pool.end(); #1670

danilloalvis opened this issue Jun 9, 2018 · 2 comments
Labels

Comments

@danilloalvis
Copy link

I'm creating a project using the node-postgress documentation:
https://node-postgres.com/features/connecting

in the documentation shows an example of a query using pool where at the end of the request it terminates the connection with the pool.end ();

I followed the same example and it worked, but when I try to do a second query this error occurs:

Cannot use a pool after calling end on the pool Error: Cannot use a pool after calling end on the pool at Pool.connect (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\pg-pool\index.js:141:19) at Pool.query (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\pg-pool\index.js:251:10) at StudentController.getAll (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\controllers\StudentController.js:11:16) at Layer.handle [as handle_request] (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\layer.js:95:5) at next (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\layer.js:95:5) at c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\index.js:281:22 at Function.process_params (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\index.js:335:12) at next (c:\Users\Danilo Torquato\Documents\projetos\elton\MaisCidadao\node_modules\express\lib\router\index.js:275:10)

@sehrope
Copy link
Contributor

sehrope commented Jun 9, 2018 via email

@charmander
Copy link
Collaborator

in the documentation shows an example of a query using pool where at the end of the request it terminates the connection with the pool.end ();

The documentation shows an example script you can run standalone; there’s no request involved. pool.end() should be called when you don’t intend to use the pool anymore, so in a web server, you would call it when shutting down (or not at all).

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

No branches or pull requests

3 participants