Skip to content

Timeout exception #7

Description

@IvAlex1986

Hello.

Sometimes I have Timeout exception when I send APN to apple server.
Below is my exception StackTrace:

System.AggregateException: One or more errors occurred. ---> System.TimeoutException: The operation has timed out.
at HttpTwo.Http2Client.d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at HttpTwo.Http2Client.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at HttpTwo.Http2Client.d__15.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at PushNotificationAPI.Controllers.AppleController.SendNotification(String jwtToken, String deviceToken, String topic, Object payload, Boolean isProduction)
at PushNotificationAPI.Controllers.AppleController.PushNotification(String kid, String iss, String topic, String authKey, Boolean isProduction, String deviceToken, Object payload)
---> (Inner Exception #0) System.TimeoutException: The operation has timed out.
at HttpTwo.Http2Client.d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at HttpTwo.Http2Client.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at HttpTwo.Http2Client.d__15.MoveNext()<---

My code here:

private AppleResponseModel SendNotification(string jwtToken, string deviceToken, string topic, object payload, bool isProduction)
        {
            var domain = isProduction ? "https://api.push.apple.com:443" : "https://api.development.push.apple.com:443";
            var uri = new Uri($"{domain}/3/device/{deviceToken}");

            var client = new Http2Client(uri);

            var headers = new NameValueCollection
            {
                {"apns-id", Guid.NewGuid().ToString()},
                {"apns-expiration", "0"},
                {"apns-priority", "10"},
                {"apns-topic", topic},
                {"authorization", $"bearer {jwtToken}"}
            };

            var body = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(payload));

            var response = client.Post(uri, headers, body).Result;

            var responseBody = Encoding.ASCII.GetString(response.Body);
            var notificationId = response.Headers["apns-id"];

            return new AppleResponseModel(response.Status, responseBody, notificationId);
        }

Could you please help me what going wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions