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

Pooled session is rejected if database was changed #515

Closed
bgrainger opened this issue Jun 12, 2018 · 2 comments
Closed

Pooled session is rejected if database was changed #515

bgrainger opened this issue Jun 12, 2018 · 2 comments

Comments

@bgrainger
Copy link
Member

bgrainger commented Jun 12, 2018

When a session is returned to the pool, it is rejected as invalid if its database has changed:

if (session.DatabaseOverride != null)
return false;

This test is unnecessarily strict. It reduces performance to close the socket and open a new one; it would be better to reuse the open connection. To accomplish this, the session could be flagged as "requires a database change".

If this flag is set, then when resetting the connection, use a COM_CHANGE_USER packet to specify the same DB as in the original connection string. Or, if ConnectionReset=false, do nothing and leave the state of the connection as-is (considering the selected DB to be part of the session state). The database should be set back to the one in the connection string, even if ConnectionReset=false; this is the expected outcome from opening a connection and is the behaviour of Connector/NET.

@bgrainger
Copy link
Member Author

If connections are being created and returned to the pool very frequently, then closing the socket can cause the client to run out of local ports and prevent future connections: #533. This would be quite unexpected when pooling is enabled, as the user would assume that a small number of physical connections are being reused.

@bgrainger
Copy link
Member Author

Fixed in 0.43.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant