matrix-org / sygnal

Sygnal: reference Push Gateway for Matrix
Apache License 2.0
164 stars 147 forks source link

iOS VOIP sometimes notifications getting significantly delayed if app is closed/in background #323

Closed harshit990 closed 1 year ago

harshit990 commented 2 years ago

iOS VOIP sometimes notifications getting delayed significantly if app is not open/in background

To Reproduce Steps to reproduce the behavior:

  1. Make sure sygnal is set up properly for VOIP, log is also showing correctly configured
  2. Make a VOIP call to your iOS device

Expected behavior VOIP notifications should get triggered and the phone should ring immediately

Smartphone (please complete the following information):

Additional context On each call attempt, phone is ringing but after significant delayed. As per attached logs, connection are being closed automatically very frequently.

Screenshot 2022-09-20 at 12 19 06 AM
harshit990 commented 2 years ago

Please anybody help me out to resolve this..

H-Shay commented 2 years ago

Which app are you using?

harshit990 commented 2 years ago

@H-Shay thanks for the reply. I am using element ios app, created custom one from element ios app. Do let me know if you need any other information

H-Shay commented 2 years ago

To be clear, you are using a custom app that you based on element ios? Looking at the logs, it's a little unclear whether this is an issue with Sygnal, your app, or Apple. Can you provide logs for a greater period of time, such as from the beginning of a one of the delayed requests to Sygnal to after the request has been processed? It might be helpful in tracking down what's happening.

harshit990 commented 2 years ago

Yes, I have compiled the element ios code with new package name, which is using custom homeserver.

I have attached log of sygnal server, which is generated from starting a call till the time second phone rings and call is disconnected by the user.

Please do let me know if you need any other information. log.txt

H-Shay commented 2 years ago

This issue might shed some light: https://github.com/matrix-org/sygnal/issues/302, let me know if the advice there is not helpful and I will keep digging.

harshit990 commented 2 years ago

@H-Shay Thanks for the reply, I don't think this is related with #302 as I have already set platform: production and also I am not able to get FCM in development build. Could you please help me out.

H-Shay commented 2 years ago

Have you been through the information here? It might be helpful.

harshit990 commented 2 years ago

@H-Shay Yes, I have already went through that but nothing solve the issue. I have installed the server through matrix-docker-ansible-deploy. I can share the other details also if you need or I can share the server details for better investigation, if you need. Please do let me know what should I do.

harshit990 commented 2 years ago

@H-Shay Could you please help me out. I am still unable to resolve this one

H-Shay commented 2 years ago

Unfortunately I am not really sure what to recommend here-it doesn't look like a bug in Syngal, as the issue is that Apns is repeatedly closing the connection. I am not an IOS developer so it's hard for me to say what might be the issue here. You could try asking in #sygnal:matrix.org for more information.

DMRobertson commented 2 years ago

On each call attempt, phone is ringing but after significant delayed.

(@manuroe does my summary here seem correct to you?)

There are many related issues: https://github.com/matrix-org/sygnal/issues?q=is%3Aissue+sort%3Aupdated-desc+ios+voip and https://github.com/vector-im/element-ios/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+voip+notification which you should read through if you haven't already. https://github.com/vector-im/element-ios/issues/4132 in particular sounds relevant; this may be a long-standing problem with Element iOS itself.

From https://github.com/matrix-org/sygnal/issues/235#issuecomment-885741255 it sounds like Element iOS uses a Notification Service Extension. You should double check this is configured properly with all the required permissions and entitlements.

Otherwise I suggest you carefully read through Apple's documentation on User Notifications and PushKit. (Note that Sygnal uses the HTTP/2 APNS API and not the legacy binary protocol.) In particular see Responding to VOIP Notifications from PushKit.

You could also try asking here or here. In general the Element-iOS team are going to be much more familiar with this problem and much better-placed to advise.

However

As per attached logs, connection are being closed automatically very frequently.

This is not a good sign. Per https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns#3394526

Verify that you aren't spamming the device. If you send too many notifications to the same device within a short timespan, APNs may treat it as a denial-of-service attack and temporarily block your server from sending notifications.

Check how often your provider server connects to APNs. If your provider server opens and closes its connection to APNs repeatedly, APNs may treat it as a denial-of-service attack and temporarily block your server from connecting.

I suggest you take a look at Troubleshoot Problems with Receiving Notifications and see if any of its suggestions help you.

DMRobertson commented 2 years ago

I don't understand why Sygnal is trying to send the same notification (at least, something with the same UUID) again and again. That doesn't sound very good.

harshit990 commented 2 years ago

@DMRobertson I have tried all 3-4 version of element ios only changing the homeserver url, sygnal url and package name but still faces same issues with all cases. Hence I think it's not related with element, must be some configurational error I have enclosed the configuration sygnal. Could you please let me know if I am doing anything wrong. I would be very grateful to you Syngal.txt

Sphinix1 commented 2 years ago

@harshit990 were you able to resolve it ?, i dont think its an element issue. i am using fluffychat and have the same issue this is my logs , Android notification works but ios notifications fail to pop-up unless the App is open `-- Logs begin at Fri 2022-05-27 06:03:00 UTC. -- Oct 06 04:51:18 fluffy matrix-sygnal[795752]: 2022-10-06 04:51:18,740 [1] INFO sygnal.access Handled request: "104.211.4.163" - - [06/Oct/2022:04:51:18 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 200 16 "-" "Synapse/1.68.0" Oct 06 04:51:18 fluffy matrix-sygnal[795752]: 2022-10-06 04:51:18,740 [1] INFO sygnal.access Handled request: "104.211.4.163" - - [06/Oct/2022:04:51:18 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 200 16 "-" "Synapse/1.68.0" Oct 06 04:51:18 fluffy matrix-sygnal[795752]: 2022-10-06 04:51:18,740 [1] INFO sygnal.access Handled request: "104.211.4.163" - - [06/Oct/2022:04:51:18 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 200 16 "-" "Synapse/1.68.0" Oct 06 04:55:18 fluffy matrix-sygnal[795752]: 2022-10-06 04:55:18,745 [1] INFO twisted Stopping factory _HTTP11ClientFactory(<function HTTPConnectionPool._newConnection..quiescentCallback at 0x7f42af944a70>, <twisted.internet.endpoints._WrapperEndpoint object at 0x7f42af941850>) Oct 06 11:13:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:13:29,004 [1] INFO sygnal.gcmpushkin [0fc3bd91-6fd6-4b3e-9db5-47174078389c] Sending (attempt 0) => ['ecxSx1lixEYwpVal_VrYhV:APA91bHBXnlMfH4gIz_ShKPeUUSkSKwiR9Nyyh13N1nE0fwVyZ2PNxySuQzu65T5a1QK2loayIys2P0EA2EDTcVhoOH0v9OUg4Z3b3ZCZGBLBRfHBAXdBTeLWcYi0tJAfZMLow1-l0'] Oct 06 11:13:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:13:29,004 [1] INFO sygnal.gcmpushkin [0fc3bd91-6fd6-4b3e-9db5-47174078389c] Sending (attempt 0) => ['ecxSx1lixEYwpVal_VrYhV:APA91bHBXnlMfH4gIz_ShKPeUUSkSKwiR9Nyyh13N1nE0fwVyZ2PNxySuQzu65T5a1QK2loayIys2P0EA2EDTcVhoOH0v9OUg4Z3b3ZCZGBLBRfHBAXdBTeLWcYi0tJAfZMLow1-l0'] Oct 06 11:13:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:13:29,009 [1] INFO twisted Starting factory _HTTP11ClientFactory(<function HTTPConnectionPool._newConnection..quiescentCallback at 0x7f42af883680>, <twisted.internet.endpoints._WrapperEndpoint object at 0x7f42af8e9ed0>) Oct 06 11:13:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:13:29,405 [1] INFO sygnal.access Handled request: "104.211.4.163" - - [06/Oct/2022:11:13:29 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 200 16 "-" "Synapse/1.68.0" Oct 06 11:13:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:13:29,405 [1] INFO sygnal.access Handled request: "104.211.4.163" - - [06/Oct/2022:11:13:29 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 200 16 "-" "Synapse/1.68.0" Oct 06 11:13:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:13:29,405 [1] INFO sygnal.access Handled request: "104.211.4.163" - - [06/Oct/2022:11:13:29 +0000] "POST /_matrix/push/v1/notify HTTP/1.0" 200 16 "-" "Synapse/1.68.0" Oct 06 11:17:29 fluffy matrix-sygnal[795752]: 2022-10-06 11:17:29,404 [1] INFO twisted Stopping factory _HTTP11ClientFactory(<function HTTPConnectionPool._newConnection..quiescentCallback at 0x7f42af883680>, <twisted.internet.endpoints._WrapperEndpoint object at 0x7f42af8e9ed0>)

`

squahtx commented 2 years ago

were you able to resolve it ?, i dont think its an element issue. i am using fluffychat and have the same issue this is my logs

This is likely due to #325, which is an incompatibility between FluffyChat and Sygnal.

squahtx commented 2 years ago

@DMRobertson I have tried all 3-4 version of element ios only changing the homeserver url, sygnal url and package name but still faces same issues with all cases. Hence I think it's not related with element, must be some configurational error I have enclosed the configuration sygnal. Could you please let me know if I am doing anything wrong. I would be very grateful to you Syngal.txt

This is a complete stab in the dark, but does specifying the push_type in the config improve things?

  com.innobins.sandsai.ios:
    certfile: /data/sandsai_apn.pem
    topic: com.innobins.sandsai
    type: apns
+   push_type: alert

  com.innobins.sandsai.ios.voip:
    certfile: /data/sands_voip_final.pem
    topic: com.innobins.sandsai
    type: apns
+   push_type: voip
MatMaul commented 1 year ago

@harshit990 did you manage to test the proposed config fix in the previous comment ? I am going to close this issue for now since it looks like a config problem on your side as you suggested, but feel free to re-open with more info if you think it's not the case.

harshit990 commented 1 year ago

I have tried with proposed config also..but nothing is working..I am still facing the same issue