Skip to content

Commit 963b9bf

Browse files
committed
Handle "packet received out-of-order" for large payloads.
1 parent 947c59f commit 963b9bf

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/MySqlConnector/MySqlClient/CommandExecutors/TextCommandExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public virtual async Task<DbDataReader> ExecuteReaderAsync(string commandText, M
6363
await m_command.Connection.Session.SendAsync(payload, ioBehavior, cancellationToken).ConfigureAwait(false);
6464
return await MySqlDataReader.CreateAsync(m_command, behavior, ioBehavior, cancellationToken).ConfigureAwait(false);
6565
}
66-
catch (Exception ex) when (payload.ArraySegment.Count > 4194304 && (ex is SocketException || ex is IOException))
66+
catch (Exception ex) when (payload.ArraySegment.Count > 4194304 && (ex is SocketException || ex is IOException || ex is MySqlProtocolException))
6767
{
6868
// the default MySQL Server value for max_allowed_packet (in MySQL 5.7) is 4MiB: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_allowed_packet
6969
// use "decimal megabytes" (to round up) when creating the exception message
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace MySql.Data.MySqlClient
4+
{
5+
public sealed class MySqlProtocolException : InvalidOperationException
6+
{
7+
internal static MySqlProtocolException CreateForPacketOutOfOrder(int expectedSequenceNumber, int packetSequenceNumber)
8+
{
9+
return new MySqlProtocolException("Packet received out-of-order. Expected {0}; got {1}.".FormatInvariant(expectedSequenceNumber, packetSequenceNumber));
10+
}
11+
12+
private MySqlProtocolException(string message)
13+
: base(message)
14+
{
15+
}
16+
}
17+
}

src/MySqlConnector/Protocol/Serialization/CompressedPayloadHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.IO.Compression;
44
using System.Threading.Tasks;
5+
using MySql.Data.MySqlClient;
56
using MySql.Data.Serialization;
67

78
namespace MySql.Data.Protocol.Serialization
@@ -87,7 +88,7 @@ private ValueTask<int> ReadBytesAsync(ArraySegment<byte> buffer, ProtocolErrorBe
8788
if (protocolErrorBehavior == ProtocolErrorBehavior.Ignore)
8889
return default(ValueTask<int>);
8990

90-
var exception = new InvalidOperationException("Packet received out-of-order. Expected {0}; got {1}.".FormatInvariant(expectedSequenceNumber, packetSequenceNumber));
91+
var exception = MySqlProtocolException.CreateForPacketOutOfOrder(expectedSequenceNumber, packetSequenceNumber);
9192
return ValueTaskExtensions.FromException<int>(exception);
9293
}
9394

src/MySqlConnector/Protocol/Serialization/ProtocolUtility.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Buffers;
33
using System.IO;
44
using System.Threading.Tasks;
5+
using MySql.Data.MySqlClient;
56
using MySql.Data.Serialization;
67

78
namespace MySql.Data.Protocol.Serialization
@@ -29,7 +30,7 @@ public static ValueTask<Packet> ReadPacketAsync(BufferedByteReader bufferedByteR
2930
if (protocolErrorBehavior == ProtocolErrorBehavior.Ignore)
3031
return default(ValueTask<Packet>);
3132

32-
var exception = new InvalidOperationException("Packet received out-of-order. Expected {0}; got {1}.".FormatInvariant(expectedSequenceNumber.Value, packetSequenceNumber));
33+
var exception = MySqlProtocolException.CreateForPacketOutOfOrder(expectedSequenceNumber.Value, packetSequenceNumber);
3334
return ValueTaskExtensions.FromException<Packet>(exception);
3435
}
3536

0 commit comments

Comments
 (0)