Timeout exception
See original GitHub issueHello.
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.<Send>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.<Send>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.<Post>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.<Send>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.<Send>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.<Post>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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:14
@Jent05 Unfortunately, I doubt that HttpTwo library supports that. When I use it, I use lock to make sure other thread finished using HttpTwo.
This happened because it is talking to wrong TCP connection somethings. I have some fixes in my fork.