Microsoft.Azure.NotificationHubs.Messaging.MessagingException: Unexpected exception encountered on CreateOrUpdateInstallationAsync

jagadesh julapalli 1 Reputation point
2022-12-15T11:35:24.907+00:00

I have a requirement where I need to update the Tag for the registration. I need to replace the old tag value with a new Tag for each device registration.
I am reading from a CSV file that has a current and new value in it and I am looping through it and updating the Tag one by one. After a certain iteration, I am seeing these exceptions and no success after that. My NotificationHub is a Standard plan and devices are approximately more than 1Million. My CSV file has almost 1 million records in it.
Note: I tried retryoptions but the same result.

My Sample Code
The code looks like below

NotificationHubSettings notificationHubSettings = new NotificationHubSettings();  
                notificationHubSettings.OperationTimeout = new TimeSpan(2, 0, 0);  
                notificationHubSettings.RetryOptions = new NotificationHubRetryOptions()  
                {  
                    Delay=new TimeSpan(0,5,0),  
                    MaxRetries=100,  
                    MaxDelay = new TimeSpan(1, 0, 0),  
                };  
                                     
                var nhClient = new NotificationHubClient("connection_string=",  
                    "hub_name", notificationHubSettings);  
                Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);  
  
                Parallel.ForEach(records, async (record) =>  
                {  
                    try  
                    {  
                        var registrations = await nhClient.GetRegistrationsByTagAsync($"oldValue", 10);  
                        var installation = new Installation();  
                        foreach (var registration in registrations)//, async (registration) =>  
                        {  
                            var type = registration.GetType();  
  
                            if (type == typeof(FcmRegistrationDescription))  
                            {  
                                var fcmreg = registration as FcmRegistrationDescription;  
  
                                installation = await nhClient.GetInstallationAsync(r.Replace(fcmreg.FcmRegistrationId, String.Empty));  
  
                                installation.Tags.Add($"{newValue}");  
  
                                await nhClient.CreateOrUpdateInstallationAsync(installation);  
  
                            }  
                            else if (type == typeof(AppleRegistrationDescription))  
                            {  
                                var applereg = registration as AppleRegistrationDescription;  
  
                                installation = await nhClient.GetInstallationAsync(applereg.DeviceToken);  
  
                                installation.Tags.Add($"{newValue}");  
  
 await nhClient.CreateOrUpdateInstallationAsync(installation);  
  
                            }  
                        }  
  
                        Console.WriteLine($"{oldValue};{newValue};device added successfully");  
                    }  
                    catch (Exception ex)  
                    {  
  
                        Console.WriteLine($"{oldValue};{newValue}; Exception: {ex.Message}");  
                    }  

----------

Exception:
Type: Microsoft.Azure.NotificationHubs.Messaging.MessagingException
Message: Unexpected exception encountered TrackingId:18ceebae-cfbe-4818-8154-4b89f20467bc,TimeStamp:2022-12-15T11:19:29.0287689Z
Source: Microsoft.Azure.NotificationHubs
Stack Trace:
at Microsoft.Azure.NotificationHubs.ExceptionsUtility.HandleUnexpectedException(Exception ex, String trackingId)
at Microsoft.Azure.NotificationHubs.NotificationHubClient.<SendRequestAsync>d__201.MoveNext()
at Microsoft.Azure.NotificationHubs.NotificationHubClient.<SendRequestAsync>d__200.MoveNext()
at Microsoft.Azure.NotificationHubs.NotificationHubClient.<GetAllEntitiesImplAsync>d__192`1.MoveNext()
at NotificationHub.UpdateRegistration.Program.<>c__DisplayClass0_0.<<Main>b__0>d.MoveNext() in C:\Source\Repos\EU-AzureFunctionNotificationHub\notificationhub-update-installation\NotificationHub.UpdateRegistration\Program.cs:line 65

InnerException 1:
Type: System.Net.Http.HttpRequestException
Message: The SSL connection could not be established, see inner exception.
Source: System.Net.Http
Stack Trace:
at System.Net.Http.ConnectHelper.<EstablishSslConnectionAsync>d__2.MoveNext()
at System.Threading.Tasks.ValueTask1.get_Result() at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult()
at System.Net.Http.HttpConnectionPool.<ConnectAsync>d__96.MoveNext()
at System.Threading.Tasks.ValueTask1.get_Result() at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult()
at System.Net.Http.HttpConnectionPool.<CreateHttp11ConnectionAsync>d__98.MoveNext()
at System.Threading.Tasks.ValueTask1.get_Result() at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult()
at System.Net.Http.HttpConnectionPool.<AddHttp11ConnectionAsync>d__73.MoveNext()
at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.<WaitWithCancellationAsync>d__1.MoveNext() at System.Threading.Tasks.ValueTask1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult() at System.Net.Http.HttpConnectionPool.<GetHttp11ConnectionAsync>d__75.MoveNext() at System.Threading.Tasks.ValueTask1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult() at System.Net.Http.HttpConnectionPool.<SendWithVersionDetectionAndRetryAsync>d__83.MoveNext() at System.Net.Http.DiagnosticsHandler.<SendAsyncCore>d__8.MoveNext() at System.Threading.Tasks.ValueTask1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at System.Net.Http.RedirectHandler.<SendAsync>d__4.MoveNext()
at System.Net.Http.HttpClient.<<SendAsync>g__Core|83_0>d.MoveNext()
at Microsoft.Azure.NotificationHubs.NotificationHubClient.<SendRequestAsync>d__201.MoveNext()

InnerException 2:
Type: System.IO.IOException
Message: Received an unexpected EOF or 0 bytes from the transport stream.
Source: System.Net.Security
Stack Trace:
at System.Net.Security.SslStream.<ReceiveBlobAsync>d__1761.MoveNext() at System.Threading.Tasks.ValueTask1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult() at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__1751.MoveNext()
at System.Net.Http.ConnectHelper.<EstablishSslConnectionAsync>d__2.MoveNext()

----------

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.