【发布时间】:2017-04-25 10:34:49
【问题描述】:
我正在使用一个很棒的库 PushSharp 将 Apple 和 Android 推送通知发送到许多客户端设备。 自上周以来,我们经常面临连接问题。在这些问题之前,我们的托管环境没有更新或发生任何事情。
问题出在ApnsConnection.cs的这一行:
stream.AuthenticateAsClient (Configuration.Host, certificates, System.Security.Authentication.SslProtocols.Tls, false);
有时 TCP 连接会在此处停止响应。大约 21 分钟后,抛出以下异常:
System.IO.IOException: Unable to read data from the connection:
An existing connection was forcibly closed by the remote host. --->
System.Net.Sockets.SocketException: An existing connection was forcibly
closed by the remote host
PushSharp 的日志显示如下:
13:11:33 | PushServiceV2 | APNS-Client[7]: Sending Batch ID=1, Count=21
13:11:33 | PushServiceV2 | APNS-Client[7]: Connecting (Batch ID=1)
13:11:33 | PushServiceV2 | APNS-Client[7]: client.ConnectAsync
13:11:33 | PushServiceV2 | APNS-Client[7]: client.Client.SetSocketOption
13:11:33 | PushServiceV2 | APNS-Client[7]: SetSocketKeepAliveValues
13:11:33 | PushServiceV2 | APNS-Client[7]: Configuration.SkipSsl:False
13:11:33 | PushServiceV2 | APNS-Client[7]: Create our ssl stream
13:11:33 | PushServiceV2 | APNS-Client[7]: stream.AuthenticateAsClient
13:32:03 | PushServiceV2 | APNS-CLIENT[7]: Send Batch Error: Batch ID=1, Error=System.IO.IOException:
可以看到,“连接被远程主机强制关闭”需要21分钟。
为了解决任何问题,我首先检查在发送一批推送通知后我断开了所有 TCP 连接。我还将批次之间的时间增加到 5 分钟。如果Apple因为我建立了许多连接而断开了我的连接,我想这应该可以解决它。但事实并非如此。
- 90%的批次都成功收发,所以证书应该是正确的;
- 我会定期检查反馈服务并删除不活动的设备;
- 我在不同位置/网络的不同开发机器上遇到了同样的问题。
关于如何进一步调查这个问题有任何线索或提示吗?
提前非常感谢!
【问题讨论】:
标签: c# sockets tcp apple-push-notifications pushsharp