При отправке сообщений FCM в firebase возникает ошибка System.IO.IOException: не удается записать данные в транспортное соединение

#c# #firebase #firebase-cloud-messaging #firebase-admin

# #c# #firebase #firebase-cloud-messaging #firebase-admin

Вопрос:

Мы используем FCM.Net проект для отправки сообщений FCM в firebase. В Google.Apis.dll версия 1.40.0.0. Мы используем тот же ApiKey для отправки сообщений, что и наши сообщения.

Если мы отправим около 100 тыс. сообщений в firebase, только 25 тыс. будут успешными.

Остальные терпят неудачу с исключением:

Во время отправки на огневую базу:

 The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.DoBeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, OverlappedAsyncResult asyncResult)
   at System.Net.Sockets.Socket.BeginMultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, Object state)
   at System.Net.Sockets.NetworkStream.BeginMultipleWrite(BufferOffsetSize[] buffers, AsyncCallback callback, Object state)
   --- End of inner exception stack trace ---
 

Во время получения ответа:

 The underlying connection was closed: An unexpected error occurred on a receive.
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContextamp; context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
 

Мы используем приведенный ниже фрагмент кода для отправки сообщений FCM и регистрации ответов.:

             try
            {
                object customData = new { Email = Email, AccountNum = AccountNum, Badge = 0 };

                using (var sender = new Sender(fireBaseServerKey))
                {
                    var message = new Message
                    {
                        RegistrationIds = new List<string> { FCMToken },
                        Notification = new Notification
                        {
                            Title = Convert.ToString(FCMTitle),
                            Body = Convert.ToString(FCMMessage),
                            Badge = "0"
                        },
                        Data = customData,
                    };

                    uniqueId = Guid.NewGuid();
                    ResponseContent result = null;
                    try
                    {
                        if (FCMToken != "" || FCMToken != null || FCMToken != string.Empty)
                        {
                            Log.Info($"Sending To Firebase Cloud Messaging - token: {FCMToken}, Email: {Email} , DeviceId: {DeviceId}, UniqueId: {uniqueId} | count: {counter}");
                            
                            result = await sender.SendAsync(message);
                            
                            Log.Info($"Sent To Firebase Cloud Messaging - token: {FCMToken}, Email: {Email} , DeviceId: {DeviceId}, UniqueId: {uniqueId} | count: {counter}");

                            if (result != null amp;amp; result.MessageResponse != null amp;amp; result.MessageResponse.Success == 1)
                            {
                                Log.Info($"Success Send To Firebase Cloud Messaging - token: {FCMToken}, Email: {Email} , DeviceId: {DeviceId}, UniqueId: {uniqueId};

                            }
                            else
                            {
                                if (result != null amp;amp; result.MessageResponse != null amp;amp; result.MessageResponse.Results[0] != null)
                                {
                                    Log.Warn($"Fail Send To Firebase Cloud Messaging - Message: {result.MessageResponse.Results[0].Error} , token: {FCMToken}, Email: {Email} , DeviceId: {DeviceId}, UniqueId: {uniqueId}");
                                }
                                else
                                {
                                    Log.Warn($"Fail Send To Firebase Cloud Messaging - token: {FCMToken}, Email: {Email} , DeviceId: {DeviceId}, UniqueId: {uniqueId}");
                                }

                                isSentSuccess = false;
                            }
                        }
                        else
                            Log.Warn($"FCM Token is Blank - token: {FCMToken}, Email: {Email} , DeviceId: {DeviceId}, UniqueId: {uniqueId}");
                    }
                    catch (
                    Exception ex)
                    {
                        Log.Error($"Firebase Cloud Messaging - SendAsync - Failed with token: {FCMToken}, UniqueId: {uniqueId}");
                        Log.Error(ex.Message);
                        Log.Error(Convert.ToString(ex.InnerException));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Send To Firebase Cloud Messaging Failed with token: {FCMToken}, UniqueId: {uniqueId}");
                Log.Error(ex.Message);
                Log.Error(Convert.ToString(ex.InnerException));
            }
 

Был бы признателен за ваш вклад в решение этой проблемы.