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

Connections not being released #1

Closed
nrempel opened this issue Jun 1, 2016 · 4 comments
Closed

Connections not being released #1

nrempel opened this issue Jun 1, 2016 · 4 comments

Comments

@nrempel
Copy link

nrempel commented Jun 1, 2016

First off - thanks for the great library!

I'm currently troubleshooting an issue with connections not being released after using withLock(). I'll update the issue as I go but if you have any pointers that would be greatly appreciated. Thanks!

@nrempel
Copy link
Author

nrempel commented Jun 1, 2016

It seems that every lock that is acquired holds a connection indefinitely.

If I perform 10 atomic operations with an advisory lock, there are 10 active connections in the database. The connections are never released so eventually, I hit my limit.

@nrempel
Copy link
Author

nrempel commented Jun 1, 2016

It looks like pg.Client() should call .end() and pg.connect() manages its own connection pool. - https://github.com/brianc/node-postgres#client-instance

I think I've fixed my issue by adding client.end() for both response cases here: https://github.com/blockai/advisory-lock/blob/master/src/index.js#L107.

I'll try to see if I can write a failing test later today

@olalonde
Copy link
Contributor

olalonde commented Jun 1, 2016

Yes, I think there's one connection created per advisoryLock(connectionString) but it should be disconnected when there are no lock held. Could you provide some sample code that's causing an issue for you? I didn't use node-postgres connection pool because I had to do connection specific stuff if I recall correctly.

edit: Oh yeah, if one connection acquires a lock, subsequent attempts to acquire the lock from the same connection will succeed but it will fail if done from a different connection.

@nrempel
Copy link
Author

nrempel commented Jun 2, 2016

Hi @olalonde thanks for getting back so quick!

I created a test for an example of the problem I'm having. #2

The test is just an example using print statements right now. I'm having a hard time making it consistently fail because of the odd case. But if you run that branch, it should give you an example of the problem I'm having.

Edit: I updated the pull request to properly include a failing test and a change to resolve the issue.

olalonde added a commit that referenced this issue Oct 19, 2016
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