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

Recycle MySqlDataReader instances #1277

Open
bgrainger opened this issue Jan 6, 2023 · 1 comment
Open

Recycle MySqlDataReader instances #1277

bgrainger opened this issue Jan 6, 2023 · 1 comment
Milestone

Comments

@bgrainger
Copy link
Member

Since there can only be one active MySqlDataReader per MySqlConnection, we could create just one instance and recycle it when it's disposed.

This could allow a user to start using a disposed reader without failure (once it's been handed out to a different caller). That currently fails with an ObjectDisposedException, so no existing code would be broken, but people could start writing new, broken code.

Related: npgsql/npgsql#1649, #1264.

@bgrainger
Copy link
Member Author

The implementation of this in v2.3.0 breaks the following code (which is an unexpected pattern, but not "wrong"):

using var connection = ...
using var reader = ...
connection.Close();
// reader disposed afterwards

#1459 (comment)

It also seems to break Dapper's QueryAsync<>, which isn't using that exact pattern (AFAICT) but may trigger some code path that exposes a race condition in MySqlConnector.

The solution may be to make MySqlDataReader as slim as possible (maybe just referencing a ResultSet and MySqlCommand?), and pool and recycle the more heavy-weight ResultSet object.

@bgrainger bgrainger reopened this Apr 21, 2024
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