9

I hope this is not too vague of a question, but I have looked far and wide but have not been able to find anything helpful for this error.

I have a .NET 4.5.2 web service tier (using ServiceStack & Dapper) that has been receiving these two errors infrequently ever since we deployed the service.

The first error:

2017-09-29 18:13:26.637 +00:00 [Error] Class: "TokenRepository" | Method: "GetToken"
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted
   --- End of inner exception stack trace ---
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at MySql.Data.MySqlClient.NativeDriver.StartSSL()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at Dapper.SqlMapper.<QueryImpl>d__125`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType)
   at myApp.Services.Data.Impl.TokenRepository.GetToken(String token) in E:\Jenkins\workspace\myApp\src\Services.Data\Impl\TokenRepository.cs:line 191

and the second...

2017-09-19 15:40:51.040 +00:00 [Error] Class: "myApp.Services.Data.Impl.SystemRepository" | Method: "GetAttributes"
System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The buffers supplied to a function was too small
   --- End of inner exception stack trace ---
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at MySql.Data.MySqlClient.NativeDriver.StartSSL()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at Dapper.SqlMapper.<QueryImpl>d__125`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType)
   at myApp.Services.Data.Impl.SystemRepository.GetAttributes() in E:\Jenkins\workspace\myApp\src\Services.Data\Impl\SystemRepository.cs:line 38

A little background on my stack:

  • .NET 4.5.2
  • Dapper 1.50.2.0
  • ServiceStack 4.5.4
  • MySQL 5.6 (using Amazon Aurora)

We do not receive this error in any other of our environments, which we are not running Aurora and simply just running MySQL 5.7.17 on Amazon RDS.

As I mentioned, these errors are sporadic and do not always happen on the same methods/services but they always happen when executing a SQL command using Dapper from the service tier to the MySQL database.

Is there anyway to debug this further or are there any known issues related to MySql/Aurora/Dapper? I have not been able to locate any after researching.

james
  • 5,006
  • 8
  • 39
  • 64
  • there maybe something about the error on this Oracle's page, but I don't have an Oracle Support Identifier to access it. Maybe someone on here can tell what they have on this: https://support.oracle.com/knowledge/Oracle%20Database%20Products/2237550_1.html – Mobigital Nov 21 '17 at 02:28
  • 1
    Hello. We're also experiencing the exact same problem on similar scenarios - .NET Web Apis & WEB MVC projects with MYSQL DB Connection deployed on AWS + Aurora. The messages we keep getting seem to point to the same problem and they come in 3 "flavours": **Attempted to read past the end of the stream**, **The message or signature supplied for verification has been altered**, **The message received was unexpected or badly formatted**. Did you find any solutions ? Thanks ! – Prisecaru Alin Dec 04 '17 at 10:05
  • 1
    @PrisecaruAlin those are the same errors we are stilling seeing, but no, I have not found any solutions. My best guess is that MySQL version `5.6.x` is the issue and it is fixed in `5.7`. Amazon just needs to update to `5.7` on Aurora. There is an [AWS support thread](https://forums.aws.amazon.com/thread.jspa?threadID=226688) of people requesting the update. I ended up implementing a "retry" library to detect failures when performing database transactions and then retrying them. It seems to be working using this work around. In C# I used [Polly](https://github.com/App-vNext/Polly) – james Dec 04 '17 at 13:41

2 Answers2

7

Check out this https://github.com/mysql-net/MySqlConnector/issues/428

I faced the same error with similar sort of tech stack. An easy fix is to add SslMode=None in your connectionString and it should work.

Dee
  • 356
  • 3
  • 17
  • 2
    Disabling transport layer encryption is not really a good solution! – Zero3 Sep 20 '18 at 13:34
  • 2
    I think if you are running your MySql or Aurora RDS instance on AWS private cloud, it does not matter if SSLMode is enabled or not. RDS will only allow connections from instances that have got RDS securityGroup attached to them so in my opinion, the solution I suggested still holds valid. – Dee Oct 02 '18 at 03:21
  • @Zero3 What should be a feasible solution for this problem? – Wackie Aug 09 '21 at 11:16
  • @Wackie suggested solutions: 1) Retry the sending once, 2) Upgrade Windows version 3) Upgrade from .NET Framework to .NET Core / .NET 5. – Zero3 Aug 10 '21 at 08:55
-1

The second error ("The buffers supplied to a function was too small") is a known issue in the .NET framework. See https://github.com/dotnet/corefx/issues/1854.

One possible workaround is retrying the connection once upon seeing this failure. It solves the problem in the mail sending use case from the GitHub issue, at least.

For what it is worth, I've seen this issue on production systems running Windows Server 2012 R2 but not on production systems running on Windows Server 2016. So I think the underlying issue might be have been fixed inbetween those versions of Windows.

Zero3
  • 594
  • 2
  • 11
  • 18