Skip to content

Conversation

@galeaspablo
Copy link
Contributor

@galeaspablo galeaspablo commented May 22, 2022

After getting a connection from a pool, and using that connection to get a binlog stream, the pool cannot be disconnected. Why? Because the pool counts the connections as still alive (the pool never decreases the count, even after the binlog stream and its connection are disconnected and dropped).

As detailed here, I believe it's best to let the binlog connection remain part of the pool, and then returning the connection slot to the pool once the binlog stream goes out of scope and is dropped.

This PR makes it possible to close a binlog stream's connection, and if the stream belonged to a pool, it returns said connection back to the pool. Both disconnecting the stream, and the return of the connection are tested.

Importantly, this PR adds BinlogStream::close to the crate's public API (previously, the Binlog Stream's connection would just hang until it timed out and it was not possible to disconnect the stream's connection).

@galeaspablo galeaspablo changed the title Binlog Stream returns its Connection to Pool BinlogStream's Conn can be closed and returned to Pool May 22, 2022
@blackbeam blackbeam merged commit d2602d1 into blackbeam:master May 31, 2022
@galeaspablo
Copy link
Contributor Author

N.B., given the stream no longer removes the connection reference from the pool, cleanup occurs when the stream is dropped. I.e., the connection is returned to the pool. Thus when the pool is dropped, the connection to the database gets dropped (no hanging connections creating CPU load in the destination db server).

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

Successfully merging this pull request may close these issues.

2 participants