Redth / PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
Other
4.38k stars 1.52k forks source link

Apns notification error: 'ConnectionError' #706

Open cDoru opened 8 years ago

cDoru commented 8 years ago

What version of PushSharp are you using?

We are using PushSharp 4.0.10

Describe your issue:

We are currently using PushSharp in an Azure Worker Role (processing pns from a database table). There is no parallel processing (meaning there is a single ApnsServiceBroker instance running continuously). Every once in a while we get a "Failed to Connect, check your firewall settings!" error. I would say 50% of the push notifications work and the other 50% fail with this message.

NOTE: We are using the apple certificate (.p12) in sandbox mode.

Do you have any idea why this happens ? Thank you

What are the steps required to reproduce this issue?

Run PushSharp as a service inside an Azure Worker Role project, or an Azure Web Role project.

Please provide any Exception Stack Traces

One or more errors occurred.

Apns notification error: 'ConnectionError' at PushSharp.Apple.ApnsServiceConnection.d2.MoveNext() Failed to Connect, check your firewall settings! at PushSharp.Apple.ApnsConnection.d25.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 PushSharp.Apple.ApnsConnection.d21.MoveNext() A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 17.110.226.164:2195 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- 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 PushSharp.Apple.ApnsConnection.d25.MoveNext()

SamVanCutsem commented 8 years ago

Any updates on this? I'm getting the same error

cDoru commented 8 years ago

No. Unfortunately for us we had a release scheduled soon so we decided to go with azure notification hub

SamVanCutsem commented 8 years ago

Our firewall blocked the outgoing packages to the APNS service. We had to open all connections to 17.0.0.0/8 (Apple owns all those IP adresses) to make it work.

idoadse commented 8 years ago

Hi, having the same issue in Azure platform (basic plan). Its happening often but not all the time. Sam, was it also happening in your case? maybe only some port/ips are blocked? is it possible that it is related to some errors in sending (e.g timeout because of bad device token)

darthgogy commented 8 years ago

I have the same problem. Sometimes I get this exception after some timeout. InternalBatchFailureRetryCount do not work with exeptions in connect() method. It's a pity.

How many times the internal batch will retry to send in case of network failure. The default value is 1.

And so System.Net.Sockets.SocketException is a network failure too.

gemsuraj commented 8 years ago

I'm too getting the same error. In start of few days it worked flawless. But suddenly it started showing connection error. I've deployed the same to another server and it worked. Tried switching the azure plan from basic to premium but sill no luck on azure. I guess azure is trying us forcefully use their notification hub.

darthgogy commented 8 years ago

I've managed to send native APNs pushes via Azure Notification Hub without any additional implementation in iOS app. I think it's a good alternative for now. What can I say about PushSharp? It's good if you need stand alone solution. If you use Azure you should use Notification Hub. It can send native pushes.

AdrianBarreraLopez commented 8 years ago

try remove blank spaces and '<' '>' the token device

arokiamanojkumar1 commented 8 years ago

I face the same issue. Does anyone have a concreconcrete solution? anything has to be done in firewall rules? Thanks

idanb007 commented 8 years ago

I face same issue , im deleting and republishing the certificate and it works for two hours and than fails (connection error ) on azure web app. on my dev machine it always works ...

mitpoo commented 8 years ago

You can resolve this issue by adding a line in your web.config file. But problem remain same if you host your website on shared hosting.

mnaoumov commented 8 years ago

@mitpoo which line are you referring to?

filip76w commented 7 years ago

I have the same problem. The problem of connection arose a few weeks ago, it worked fine before. Is there any solution to this?

mitpoo commented 7 years ago

That issue is due to server trust level security. I have used PHP pushnotification code and called that function from .net application using Web Request.

Let me know if you have any query for same.

Thank you, Pooja Doshi

On Nov 2, 2016 5:09 PM, "filip76w" notifications@github.com wrote:

I have the same problem. The problem of connection arose a few weeks ago, it worked fine before. Is there any solution to this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Redth/PushSharp/issues/706#issuecomment-257841163, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTyDRXSp8tTF_7CDzgYywaUQW9DmeZHks5q6HZ1gaJpZM4IharS .

filip76w commented 7 years ago

I send notifications directly from an asp.net website. What do you mean by "adding a line in your web.config" in your previous answer?

mitpoo commented 7 years ago

I have added that line in web.config that works fine for few days on server but again same issue arose. I am sorry, i forgot to update my comment. But if you are using shared hosting then you will sure face trust level issue for sending pushnotification using .net application.

Thanks Pooja Doshi

On Nov 2, 2016 7:35 PM, "filip76w" notifications@github.com wrote:

I send notifications directly from an asp.net website. What do you mean by "adding a line in your web.config" in your previous answer?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Redth/PushSharp/issues/706#issuecomment-257873844, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTyDUvg7kbgmalrlhzwrRIVgq9FgBq3ks5q6JjDgaJpZM4IharS .

darthgogy commented 7 years ago

Problem is in ApnsConnection.cs (line 143). We have try-finally block there. Configuration.InternalBatchFailureRetryCount useless in this situation because there is no catch there. So if "await connect ()" fails it will not retry to connect. You can clone PushSharp git and fix it by yourself. https://github.com/Redth/PushSharp/blob/5abac610539174a772fc0907403ddbf042c66856/PushSharp.Apple/ApnsConnection.cs#L143

mitpoo commented 7 years ago

Ok.. will try and update you soon.. Thank you

On Nov 2, 2016 7:59 PM, "Ivan Hladchenko" notifications@github.com wrote:

Problem is in ApnsConnection.cs (line 143). We have try-finally block there. Configuration.InternalBatchFailureRetryCount useless in this situation because there is no catch there. So if "await connect ()" fails it will not retry to connect. You can clone PushSharp git and fix it by yourself. https://github.com/Redth/PushSharp/blob/ 5abac610539174a772fc0907403ddbf042c66856/PushSharp.Apple/ ApnsConnection.cs#L143

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Redth/PushSharp/issues/706#issuecomment-257880750, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTyDYG63v35kdG5Ki9j53x1hJG2pZNiks5q6J4ugaJpZM4IharS .

mitpoo commented 7 years ago

Will it work if i use new code from git and integrate same in my .net application and publish same and upload on Godaddy server on medium trust level? As when i am calling APNSConfiguration function it throws an error of security permission which is not yet resolve, i guess.

Let me know for same.. Thank you

On Nov 2, 2016 8:00 PM, "Pooja Doshi" pooja.doshi1404@gmail.com wrote:

Ok.. will try and update you soon.. Thank you

On Nov 2, 2016 7:59 PM, "Ivan Hladchenko" notifications@github.com wrote:

Problem is in ApnsConnection.cs (line 143). We have try-finally block there. Configuration.InternalBatchFailureRetryCount useless in this situation because there is no catch there. So if "await connect ()" fails it will not retry to connect. You can clone PushSharp git and fix it by yourself. https://github.com/Redth/PushSharp/blob/5abac610539174a772fc 0907403ddbf042c66856/PushSharp.Apple/ApnsConnection.cs#L143

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Redth/PushSharp/issues/706#issuecomment-257880750, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTyDYG63v35kdG5Ki9j53x1hJG2pZNiks5q6J4ugaJpZM4IharS .

mitpoo commented 7 years ago

Hi,

Still this pushsharp code is again filed to run on medium trust level in Godaddy shared hosting. So, Issue is still not resolved for secure APNS configuration class. May be you did not get what is my actual issue is. I am facing security permission issue while creating APNS configuration on medium trust using asp.net application. So, Pushsharp is not that much helpful if you are working with shared hosting.

Thanks, Pooja Doshi

On Mon, Nov 7, 2016 at 5:48 PM, Pooja Doshi pooja.doshi1404@gmail.com wrote:

Will it work if i use new code from git and integrate same in my .net application and publish same and upload on Godaddy server on medium trust level? As when i am calling APNSConfiguration function it throws an error of security permission which is not yet resolve, i guess.

Let me know for same.. Thank you

On Nov 2, 2016 8:00 PM, "Pooja Doshi" pooja.doshi1404@gmail.com wrote:

Ok.. will try and update you soon.. Thank you

On Nov 2, 2016 7:59 PM, "Ivan Hladchenko" notifications@github.com wrote:

Problem is in ApnsConnection.cs (line 143). We have try-finally block there. Configuration.InternalBatchFailureRetryCount useless in this situation because there is no catch there. So if "await connect ()" fails it will not retry to connect. You can clone PushSharp git and fix it by yourself. https://github.com/Redth/PushSharp/blob/5abac610539174a772fc 0907403ddbf042c66856/PushSharp.Apple/ApnsConnection.cs#L143

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Redth/PushSharp/issues/706#issuecomment-257880750, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTyDYG63v35kdG5Ki9j53x1hJG2pZNiks5q6J4ugaJpZM4IharS .

bidianqing commented 7 years ago

IIS Express is Succeeded and IIS is Failed

yen-ssu commented 7 years ago

I don't think this is IIS issue. I try to test connection to sandbox server using Powershell. It sometimes succeeds, sometimes fails. If I flush dns cache, my push sharp can work again. This is dns problem. So I decided to disable dns cache on my windows server, then everything is fine @bidianqing Through my test, I recommend to test apns push with production server

Sample command: Test-NetConnection -ComputerName gateway.sandbox.push.apple.com -Port 2195 Test-NetConnection -ComputerName feedback.sandbox.push.apple.com -Port 2196 Test-NetConnection -ComputerName gateway.push.apple.com -Port 2195 Test-NetConnection -ComputerName feedback.sandbox.push.apple.com -Port 2196

ipconfig /flushdns

yen-ssu commented 7 years ago

@bidianqing how you fixed your problem?

bidianqing commented 7 years ago

@yen-ssu image image image

sercanparker commented 7 years ago

@SamVanCutsem I am facing same issue for API project hosted on Azure App Service. I could not find any firewall settings for App Service, could you describe firewall settings on portal ?

sercanparker commented 7 years ago

@bidianqing Could you give any screenshots in English ?

bidianqing commented 7 years ago

@sercanparker Find the corresponding application pool,Right click,view Advanced Settings, Process model→ image custom account

rammi44 commented 6 years ago

I am facing the same issue.. Our application is hosted on everleap. How to resolve this issue..??

fatim commented 6 years ago

Same issue on Azure WebApp.