Skip to content

Handle or forbid putting of closed connections into a pool #33

@Totktonada

Description

@Totktonada

Case: a connection is acquired from a pool, then it is closed with <connection object>:close() and then it is put back to the pool.

Note: the code uses <connection object>.usable to mark closed connections or ones that was put back to a pool.

The documentation does not state that putting of closed connections is forbidden. The code don't give an error in the case and even correctly calculates that one more connection can be acquired (<pool object>.queue:put(nil) under hood). However this connection has GC callback that will close underlying raw connection and will allow to acquire one more from the pool: here the math fails.

(1) We can remove the GC callback and close the underlying connection at putting a closed connection to a pool.

(2) We however can give an error in the case: when a user attempt to put a connection with <connection object>.usable == false field, do nothing and give an error. We do not distingush between closed and released (put to a pool) connections: both have <connection object>.usable set to false. If we'll forbid to put closed connections, then we'll also forbid to put a connection twice. This looks as good protection from mistakes.

If we really need to put a manually closed connection to a pool, let's introduce one more flag to distinguish closed and released (put to a pool) connections.

I propose to implement the approach (2).

NB: Don't forget to add a test to verify the new behaviour.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingprio7

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions