Skip to content

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

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

Closed
Totktonada opened this issue Nov 22, 2019 · 8 comments · Fixed by #42
Closed

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

Totktonada opened this issue Nov 22, 2019 · 8 comments · Fixed by #42
Assignees
Labels
bug Something isn't working prio7

Comments

@Totktonada
Copy link
Member

Totktonada commented Nov 22, 2019

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.

@Totktonada Totktonada added the bug Something isn't working label Nov 22, 2019
@Totktonada
Copy link
Member Author

May be related to TNT-24.

@LeonidVas LeonidVas self-assigned this Sep 4, 2020
LeonidVas added a commit that referenced this issue Sep 9, 2020
If the connection belongs to a connection pool, it must be
returned to the pool when calling "close" without actually
closing the connection. All connections will be closed when
poll:close() will be called. The same behavior is used in
JDBC connection pool.
With this change, an attempt to merge an unusable connection
is no longer valid. But before it was valid, so now it's just
a NOP.

Fixed #33
LeonidVas added a commit that referenced this issue Sep 9, 2020
If the connection belongs to a connection pool, it must be
returned to the pool when calling "close" without actually
closing the connection. All connections will be closed when
poll:close() will be called. The same behavior is used in
JDBC connection pool.
With this change, an attempt to merge an unusable connection
is no longer valid. But before it was valid, so now it's just
a NOP.

Fixed #33
LeonidVas added a commit that referenced this issue Sep 10, 2020
If the connection belongs to a connection pool, it must be
returned to the pool when calling "close" without actually
closing the connection. All connections will be closed when
poll:close() will be called. The same behavior is used in
JDBC connection pool.
With this change, an attempt to merge an unusable connection
is no longer valid. But before it was valid, so now it's just
a NOP.

Fixed #33
@Totktonada
Copy link
Member Author

Alternative: Just remove close method from a connection from a pool.

@LeonidVas
Copy link
Contributor

LeonidVas commented Sep 26, 2020

Alternative: Just remove close method from a connection from a pool.

Backward compatibility will be broken (and strange decision, IMHO). Now the behavior of the connection in the case of "close" is close to the same as in the "JDBC Connection Pool".

@Totktonada
Copy link
Member Author

Backward compatibility will be broken

I disagree. It does not work correctly now.

@LeonidVas
Copy link
Contributor

Backward compatibility will be broken

I disagree. It does not work correctly now.

Why? As far as I remember, I can take a connection from the pool, close it and put it in the pool now. And this will be a valid code.

@Totktonada
Copy link
Member Author

Backward compatibility will be broken

I disagree. It does not work correctly now.

Why? As far as I remember, I can take a connection from the pool, close it and put it in the pool now. And this will be a valid code.

So why this issue exists?

@LeonidVas
Copy link
Contributor

Backward compatibility will be broken

I disagree. It does not work correctly now.

Why? As far as I remember, I can take a connection from the pool, close it and put it in the pool now. And this will be a valid code.

So why this issue exists?

After some discussion, we decided to leave the close method for connection from the pool and add an exception throwing from the pool: put () method in case the connection has been closed earlier (close is synonymous with put in this context).

@Totktonada
Copy link
Member Author

May be related to TNT-24.

The code in the internal issue does not use :close() (just pool:get(), conn:execute(), pool:put()), so the issue does not look related.

LeonidVas added a commit that referenced this issue Oct 6, 2020
If the connection belongs to a connection pool, it must be
returned to the pool when calling "close" without actually
closing the connection. All connections will be closed when
poll:close() will be called. The same behavior is used in
JDBC connection pool.
With this change, an attempt to "put" an unusable connection
is no longer valid.

Fixed #33
LeonidVas added a commit that referenced this issue Oct 15, 2020
If the connection belongs to a connection pool, it must be
returned to the pool when calling "close" without actually
closing the connection. All connections will be closed when
poll:close() will be called. The same behavior is used in
JDBC connection pool.
With this change, an attempt to "put" an unusable connection
is no longer valid.

Code that doesn't test anything has been removed from the tests.

Fixed #33
LeonidVas added a commit that referenced this issue Oct 15, 2020
If the connection belongs to a connection pool, it must be
returned to the pool when calling "close" without actually
closing the connection. All connections will be closed when
poll:close() will be called. The same behavior is used in
JDBC connection pool.
With this change, an attempt to "put" an unusable connection
is no longer valid.

Code that doesn't test anything has been removed from the tests.

Fixed #33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working prio7
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants