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

Is the count correct? #167

Open
ioquatix opened this issue Oct 28, 2022 · 2 comments
Open

Is the count correct? #167

ioquatix opened this issue Oct 28, 2022 · 2 comments

Comments

@ioquatix
Copy link

::Thread.current[@key] = @available.pop(options[:timeout] || @timeout)

It seems to me, we increment the count, and then perform an operation to get a connection, which may time out.

It seems the invariant of checkout can be violated, i.e. it increments the count, even though it fails to check out a connection.

This is actually, somewhat suprisingly, handled correctly in with because the timeout interrupt is deferred until within the begin block which has ensure checkout which correctly decrements the count, even in the case of an exception. But during that time, the actual count seems incorrect.

It would appear this makes it tricky/unsafe to use checkout and checkin in general, since the count invariant can be violated.

@mperham
Copy link
Owner

mperham commented Oct 28, 2022

Yeah, I can see some shady edge cases. I wonder if we can write some tests which surface the bad behavior.

@ioquatix
Copy link
Author

I tried to write some but ran out of time.

I think anything that calls checkout with a timeout can fail, i.e. it's very hard to write safe code that uses checkout and checkin directly.

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