Skip to content

MySqlProtocolException: Packet received out-of-order #496

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

Closed
stulzq opened this issue May 14, 2018 · 9 comments
Closed

MySqlProtocolException: Packet received out-of-order #496

stulzq opened this issue May 14, 2018 · 9 comments
Labels
waiting for answer Needs more information from the bug reporter

Comments

@stulzq
Copy link

stulzq commented May 14, 2018

Hello,I get a exception in the use of mysqlconnector.
mysqlconnector version:0.38
mysql version:5.5.58

Exception:

MySql.Data.MySqlClient.MySqlProtocolException: Packet received out-of-order. Expected 2; got 115.
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Protocol.Serialization.ProtocolUtility.DoReadPayloadAsync(BufferedByteReader bufferedByteReader, IByteHandler byteHandler, Func`1 getNextSequenceNumber, ArraySegmentHolder`1 previousPayloads, ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\Serialization\ProtocolUtility.cs:line 462
   at MySqlConnector.Protocol.Serialization.StandardPayloadHandler.ReadPayloadAsync(ArraySegmentHolder`1 cache, ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\Serialization\StandardPayloadHandler.cs:line 37
   at MySqlConnector.Core.ServerSession.ReceiveReplyAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 599
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 1048
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySqlConnector.Core.ServerSession.<TryResetConnectionAsync>d__57.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 377
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__10.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs:line 72
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__10.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs:line 141
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__83.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 397
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__25.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 170
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlConnection.Open() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 156
   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2827
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570
   at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443
   at DotNetCore.CAP.MySql.MySqlStorageTransaction.UpdateMessage(CapReceivedMessage message)
   at DotNetCore.CAP.Processor.States.StateChanger.ChangeState(CapReceivedMessage message, IState state, IStorageTransaction transaction)
   at DotNetCore.CAP.Processor.States.StateChangerExtensions.<ChangeStateAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at DotNetCore.CAP.DefaultSubscriberExecutor.<ExecuteAsync>d__11.MoveNext()

The main exception message is Packet received out-of-order. Expected 2; got 115.,but sometimes the "got" numbers change:Packet received out-of-order. Expected 2; got 1.

My business scenario is to execute three delete statements,contains subqueries.such as delete form user where userid in (select ...)

Could you give me a suggestion or solution?

@bgrainger
Copy link
Member

Do you have a small, self-contained repro that demonstrates the problem?

Alternatively, can you get a Wireshark packet capture of the DB connection leading up to the crash?

@bgrainger bgrainger added the waiting for answer Needs more information from the bug reporter label May 15, 2018
@dimter2016
Copy link

dimter2016 commented May 16, 2018

I have a problem like this.
mysqlconnector version:0.32
mysql version: community-5.7.19.0

MySql.Data.MySqlClient.MySqlProtocolException: Packet received out-of-order. Expected 1; got 2.     
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     
at MySqlConnector.Protocol.Serialization.ProtocolUtility.DoReadPayloadAsync(BufferedByteReader bufferedByteReader, IByteHandler byteHandler, Func`1 getNextSequenceNumber, ArraySegmentHolder`1 previousPayloads, ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\Serialization\ProtocolUtility.cs:line 462     
at MySqlConnector.Protocol.Serialization.StandardPayloadHandler.ReadPayloadAsync(ArraySegmentHolder`1 cache, ProtocolErrorBehavior protocolErrorBehavior, IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\Serialization\StandardPayloadHandler.cs:line 37    
at MySqlConnector.Core.ServerSession.ReceiveReplyAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 492  --- End of stack trace from previous location where exception was thrown ---     
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     
at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 856    
 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()     
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)     at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)  --- End of stack trace from previous location where exception was thrown ---    
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
 at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()     
at MySqlConnector.Core.ServerSession.<TryResetConnectionAsync>d__57.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 280  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__0.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs:line 92  --- End of stack trace from previous location where exception was thrown ---     
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     
at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__77.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 355  --- End of stack trace from previous location where exception was thrown ---    
 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__19.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 152  --- End of stack trace from previous location where exception was thrown ---     
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     
at MySql.Data.MySqlClient.MySqlConnection.Open() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 137     
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)     
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)     
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)     
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()    
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()     

@dimter2016
Copy link

#267 is like this,but has be closed

@bgrainger
Copy link
Member

@dimter2016 Can you get a packet capture (with Wireshark or similar) for when the problem happens?

@stulzq
Copy link
Author

stulzq commented May 17, 2018

Hello,In these days,I pull out that piece of code,but I can't reproduce that problem.Our entire project is using mysqlconnector,only here is this exception.I will update mysqlconnector to 0.40.3, and then I will see if this problem still occurs.Follow-up situation I will explain here.Thanks.

@stulzq
Copy link
Author

stulzq commented May 24, 2018

@bgrainger We have updated the Mysqlconnector to 0.40.3, but I found this problem through the log, so I repeatedly checked the code, found that the method of executing three SQL (three SQL execution is a different method) is the Async method, but we did not use await to make the call, may be the question Problems caused by. I'll look at it again to see if it will happen again and continue to update it here.

@bgrainger
Copy link
Member

It is not permitted to have multiple in-flight async operations on the same connection at the same time; you do have to await any existing operation before starting a new one.

However, you should also get a more helpful exception message (better than Packet received out-of-order) that helps you understand the problem and fix it. So if you are able to get a repro or a code sample that shows the problem, that would be good as it could help me identify where there is a missing check (for this invalid behaviour) in the code.

@stulzq
Copy link
Author

stulzq commented May 29, 2018

This problem has been solved.

@stulzq stulzq closed this as completed May 29, 2018
@mysql-net mysql-net deleted a comment from nestorrojas07 Feb 3, 2020
@LeonardoDaLuz
Copy link

LeonardoDaLuz commented Mar 18, 2023

I used it in the dispose of my activity log service, so that this would not interfere with the response time to the frontend. I mistakenly used ExecuteAsync, without using await. It happened that aspnet tried to kill the instance before finishing the execution of the query, then this problem was triggered. I switched to Execute, without async and it solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for answer Needs more information from the bug reporter
Development

No branches or pull requests

4 participants