2017-04-25 211 views
0

我正在使用一個偉大的庫PushSharp來向許多客戶端設備發送Apple推送通知&。 自上週以來,我們經常面臨連接問題。在這些問題發生之前,我們的託管環境沒有任何更新或任何更新。爲什麼我的與Apple APNS的TCP連接掛起並強行斷開

的問題是在這條線在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分鐘。如果蘋果因爲建立了許多連接而斷開我的連接,我想這應該可以解決它。但事實並非如此。

  • 所有批次的90%都成功發送和接收,所以證書應該是正確的;
  • 我會定期檢查反饋服務並刪除不活動的設備;
  • 我有一個不同的位置/網絡上的不同的開發機器上同樣的問題。

有沒有人就如何進一步調查此問題的任何線索或提示?

非常感謝提前!

回答

0

我認爲我們只打連接數的限制。我已閱讀本文件:Troubleshooting Push Notifications,把此行注:

另一種可能性是,你已經連接的次數太多的APN 並進一步連接已被暫時封鎖。正如 本地和遠程通知編程指南中介紹, 開發商也將打開連接並保持打開狀態。如果 連接打開和關閉多次,將APN的把它當作一個 拒絕服務攻擊和今後一個時期的時間塊連接。

我重寫了我的實現和使用PushSharp,以便儘可能少地創建和關閉TCP連接。現在運行幾天沒有任何問題。在日誌記錄中,我發現連接每天只能由蘋果斷開連接,並且PushSharp很好地重新連接。