Description
I have recently switched to using ProxySQL in front of my mysql database instances, and noticed that one of many of my deployed projects using MySqlConnector started to intermittently fail.
A query SELECT
ing a field of type text COLLATE utf8_bin NOT NULL
is hitting the following exception:
code:
using (var connection = new MySqlConnection($"...")
{
connection.Open();
connection.QueryFirstOrDefault<string>(@"SELECT group_desc FROM phpbb_groups");
}
exception:
Unhandled exception. System.AggregateException: One or more errors occurred. (Failed to read the result set.)
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Failed to read the result set.
---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MySqlConnector.Protocol.Serialization.ByteArrayReader.ReadLengthEncodedInteger() in /_/src/MySqlConnector/Protocol/Serialization/ByteArrayReader.cs:line 124
at MySqlConnector.Protocol.Serialization.ByteArrayReader.ReadLengthEncodedByteString() in /_/src/MySqlConnector/Protocol/Serialization/ByteArrayReader.cs:line 149
at MySqlConnector.Protocol.Payloads.OkPayload.Create(ReadOnlySpan`1 span, Boolean deprecateEof, Boolean clientSessionTrack) in /_/src/MySqlConnector/Protocol/Payloads/OkPayload.cs:line 45
at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior)
at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet() in /_/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataReader.cs:line 130
at MySql.Data.MySqlClient.MySqlDataReader.CreateAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary`2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataReader.cs:line 391
at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList`1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 62
at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in /_/src/MySqlConnector/MySql.Data.MySqlClient/MySqlCommand.cs:line 210
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in /_/Dapper/SqlMapper.cs:line 1051
at Dapper.SqlMapper.QueryRowImpl[T](IDbConnection cnn, Row row, CommandDefinition& command, Type effectiveType) in /_/Dapper/SqlMapper.cs:line 1177
at Dapper.SqlMapper.QueryFirstOrDefault[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 761
To make things more interesting, this only happens when using a specific mysql database user. The user which causes the issue is also in use on a different high load application which also uses MySqlConnector (latest version in both cases).
Running the same query from a CLI mysql client does not seem to cause any unexpected issue. The other application using the same user makes use of MySqlDataAdapter
and MySqlCommand
, if that helps pinpoint in any way.
To reiterate, this only happens with the text
type. Other queries accessing varchar
or number types never hit this same issue.
I understand this is likely going to take a bit of investigating, but am posting before I have a complete grasp of the situation in case anyone is able to more easily understand what is going on. My next step will be to get MySqlConnector in a debuggable state to see what the underlying data looks like.