Sendgrid-csharp: Could not create SSL/TLS secure channel

Created on 10 Aug 2017  路  30Comments  路  Source: sendgrid/sendgrid-csharp

Issue Summary

We are seeing intermittent WebException when trying to send an email using SendGridClient.SendEmailAsync method.

Steps to Reproduce

  1. Create SendGridClient
  2. Call SendEmailAsync
  3. A small percentage of the calls (~0.1%) fails with the following error:
    System.Net.WebException The request was aborted: Could not create SSL/TLS secure channel.

Technical details:

  • sendgrid-csharp Version: 9.5.1
  • .NET Version: 4.6
support

All 30 comments

Hello @evgenyAtInsightly,

This seems like a networking issue. I suggest you implement a retry strategy as discussed here.

With Best Regards,

Elmer

Is this a networking issue on the SendGrid's side? We are not seeing any networking errors from any other integrations we have running on the same machine.

Hi @evgenyAtInsightly,

I have not seen any other reports here (on any of our SDKs) on that, but the issues posted here are generally for SDK issues. To get help on networking issues, please reach out to our support team at https://support.sendgrid.com.

Thanks!

Elmer

We have been seeing the same thing starting roughly 2 weeks ago. It is a small percentage of calls, but it is definitely more than before. I was already planning to build in a retry mechanism, so I will prioritize this, but I guess it would be good for SendGrid to be aware. By @evgenyAtInsightly, you are not alone ;)

Thanks for the confirmation @eriksteinebach! Could you please also reach out to our support team to get some traction on this?

I can add that we're also experiencing issues with this.

Hello @gliljas,

Thanks for letting us know!

@eriksteinebach @gliljas,

If you have a moment, could you please open a support ticket?

With Best Regards,

Elmer

We are also experiencing this issue:

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SendGrid.Helpers.Reliability.RetryDelegatingHandler.<SendAsync>d__4.MoveNext() in C:\Users\ethomas\Documents\GitHub\sendgrid-csharp\src\SendGrid\Reliability\RetryDelegatingHandler.cs:line 50 --- 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.Net.Http.HttpClient.<FinishSendAsync>d__58.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 SendGrid.SendGridClient.<MakeRequest>d__23.MoveNext() in C:\Users\ethomas\Documents\GitHub\sendgrid-csharp\src\SendGrid\SendGridClient.cs:line 250 --- 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 SendGrid.SendGridClient.<RequestAsync>d__24.MoveNext() in C:\Users\ethomas\Documents\GitHub\sendgrid-csharp\src\SendGrid\SendGridClient.cs:line 290 --- 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 SendGrid.SendGridClient.<SendEmailAsync>d__25.MoveNext() in C:\Users\ethomas\Documents\GitHub\sendgrid-csharp\src\SendGrid\SendGridClient.cs:line 301 --- 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 <ignored>.EmailMessenger.Sendgrid.SendGridEmailMessenger.<SendAsync>d__8.MoveNext() in C:\<ignored>\<ignored>\src\<ignored>\EmailMessenger\Sendgrid\SendGridEmailMessenger.cs:line 71 The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)

Note, we're explicit in regards to setting which protocol we're using.

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

We've tried multiple combinations as well. Ig. "Tls11 | Tls12" as well.

Version: 9.9.0
Sendgrid C# Official Client
.Net 4.6
Running in an Azure Website instance

Hello @etsms,

Is your issue also intermittent? If so, what would you say the frequency is?

When this happens, if you retry, does the email go through?

With Best Regards,

Elmer

I'll reply too. We're experiencing this intermittently, and it may be slightly related to an open support ticket we have, where the Sendgrid load balancer dies. Our retry mechanisms are mostly handling it.

I'll add a bit of logging, as outlined here:

https://stackoverflow.com/questions/6232746/c-sharp-httpwebrequest-sec-i-renegotiate-intermittent-errors

Thanks for the additional feedback @gliljas! I will check with our support team to dig deeper.

@thinkingserious yes, intermittent.

We send roughly 5,000 emails with sendgrid between the hours of 9AM to 5PM EST. There is no pattern in which the failure occurs. Today we saw 98 of the 5000 emails fail with the aforementioned error (Could not create SSL/TLS).

Some days it's worse.

The sendgrid c# sdk has a retry handler mechanism already and we leave it set to it's default settings.

Thanks for the additional feedback @etsms!

@gliljas, @etsms, @eriksteinebach, @evgenyAtInsightly,

Getting to the bottom of this issue will require assistance from our support team, who have the required tools to troubleshoot this issue, as the issue is on our server side. You may reach out to them here and please refer them back to this thread.

With Best Regards,

Elmer

We are in the process of switching from using SMTP to using the SendGrid API and are running into this same issue with "could not create secure channel" error intermittently being thrown. sounds like i need to contact sendgrid support as per the last comment, but thought i'd add my setup here too.

.net v4.6.2
sendgrid client v9.8.0

I also started seeing this on a customers solution.
Its running an older 6.3.4 client, which could make it seem like its not related to changes in the library, but maybe on infrastructure wise at sendgrid?

Thanks for the additional information @TheBekker!

Please reach out to the support team and reference this issue.

With Best Regards,

Elmer

We are also experiencing this issue with .NET 4.5.2 and SendGrid client 9.9.0. Are there any updates on the status of this issue? Do I also need to create a support ticket?
Thank you.

Some official public infomation would be nice, instead of sending each of us to support

Hello @TheBekker,

I will check with our support team to find out if there is a resolution for this.

With Best Regards,

Elmer

I am also experiencing this issue and have a ticket logged with your support team, but they think I am requesting a code review or QA on our application. I'm just wondering if there's a resolution for this, yet.
I have tried the things mentioned here:

https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel

Relevant:
SendGrid client 9.9.0
C# .NET 4.6.1

Hello @dziegler2,

Do you mind sharing your support ticket number?

With Best Regards,

Elmer

@thinkingserious the ticket number is 1593973

I was passed to second level support yesterday.

Perfect, hopefully L2 support will be able to assist.

FYI - created a ticket 1700519 with sendgrid support. details of the stack are at https://github.com/Jericho/StrongGrid/issues/254
Thank you

since we did have an occurrence of this recently, I do see some pattern. We do process emails in parallel & if at a given time number of those processes is > 10, each calling out apis, possibly rate limit hits & we get this error (exception details below). And of course, after retrying that same call works afterwards.

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Pathoschild.Http.Client.FluentClient.<SendImplAsync>d__29.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 Pathoschild.Http.Client.FluentClient.<<SendAsync>b__21_0>d.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 Pathoschild.Http.Client.Retry.RetryCoordinator.<ExecuteAsync>d__5.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 Pathoschild.Http.Client.Internal.Request.<Execute>d__46.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 Pathoschild.Http.Client.Internal.Request.<AsMessage>d__40.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 StrongGrid.Utilities.Extensions.<AsSendGridObject>d__7``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 System.Runtime.CompilerServices.TaskAwaiter``1.GetResult() at ThreeBirds.EmailProviders.SendGrid.SendGridProvider.GetSendGridDomain(String emailPipeSettingsJson)

and we do have code that sets
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; ServicePointManager.Expect100Continue = true;

I have also received this error while using SendGidClient from a WindowsService . When I looked to the event viewer , I have found a SChannel Error - SChannel A fatal alert was received from the remote endpoint. The TLS protocol defined fatal alert code is 20. The description of 20 says -. (https://blogs.msdn.microsoft.com/kaushal/2012/10/05/ssltls-alert-protocol-the-alert-codes/)
bad_record_mac
Received a record with an incorrect MAC. This message is always fatal

I am just putting it here as it might provide some insight.

@kylearoberts,

@vkpnipnia64's comment may shed some light on this issue. The error is: "Received a record with an incorrect MAC. This message is always fatal."

I execute some rules for IIS best practices and SendGrid starts giving me this problem.

image

image

SendGridClientOptions o = new SendGridClientOptions()
{
ReliabilitySettings = new SendGrid.Helpers.Reliability.ReliabilitySettings(5, new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 30), new TimeSpan(0, 0, 10)),
ApiKey = apiKey
};


 var client = new SendGridClient(o);
var from = new EmailAddress(fromEmail, fromName);
var to = new EmailAddress(toEmail);
var plainTextContent = textMsg;
var htmlContent = htmlMsg;
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
Response res = await client.SendEmailAsync(msg);

Hello @evgenyAtInsightly,

Thanks for submitting a GitHub issue! We are very sorry that you are running into this problem. In order to better serve you, as this does not present itself as a library specific issue, we would like to ask that you reach out to our support team at https://support.sendgrid.com.

Thank you!

SendGrid DX Team

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bogacg picture bogacg  路  3Comments

lijaso picture lijaso  路  3Comments

CalvinFengDatacom picture CalvinFengDatacom  路  4Comments

shervinw picture shervinw  路  4Comments

eat-sleep-code picture eat-sleep-code  路  3Comments