parse-community / parse-server-push-adapter

A push notification adapter for Parse Server
https://parseplatform.org
MIT License
85 stars 100 forks source link

Parse-Server Crash on APNs Timeout #66

Closed doodyparizada closed 6 years ago

doodyparizada commented 7 years ago

Transferred from https://github.com/ParsePlatform/parse-server/issues/3637

Issue Description

Using the REST endpoint for sending APNS push, sometimes the service times out and causes parse-server to crash...

Steps to reproduce

Just running this following curl a few times until the app crashes:

curl -H 'X-Parse-Application-Id: XXX' \
     -H 'X-Parse-Master-Key: XXX' \
     -d '{"where": {"user": {"$inQuery": {"className": "_User", "where": {"objectId": {"$in": ["UID1", "UID2"]}}}}}, "data": {"title": "my title", "alert": "mi alert"}}' \
     'http://localhost:1337/parse/push'

Expected Results

parse-server should catch the exception and either retry or fail with an error message (not crash the whole process).

Actual Outcome

parse-server is crashing on:

/parse/node_modules/parse-server/lib/ParseServer.js:401
            throw err;
            ^

Error: Connect timed out
    at Connection.<anonymous> (/parse/node_modules/apn/lib/connection.js:226:36)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)

Environment Setup

Logs/Trace

I caught two types of crashes:

ERR! parse-server-push-adapter APNS cannot find vaild connection for b73bd323f4e1a5427a82e2463c79e0b9cb34f95e8154e78ce7a2511021282ec5
/parse/node_modules/parse-server/lib/ParseServer.js:401
            throw err;
            ^

Error: certificate has expired: 2017-03-09T07:49:49.000Z
    at validateCredentials (/parse/node_modules/apn/lib/credentials/validate.js:12:9)
    at /parse/node_modules/apn/lib/connection.js:163:5
    at _fulfilled (/parse/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/parse/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/parse/node_modules/q/q.js:796:13)
    at /parse/node_modules/q/q.js:604:44
    at runSingle (/parse/node_modules/q/q.js:137:13)
    at flush (/parse/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)

But my certificate is not expired - retrying works.

and:

/parse/node_modules/parse-server/lib/ParseServer.js:401
            throw err;
            ^

Error: Connect timed out
    at Connection.<anonymous> (/parse/node_modules/apn/lib/connection.js:226:36)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)

just timing out on the connection.

tylerarnold commented 7 years ago

I see the same behavior. It would be far nicer to properly catch the error and not blow up.

woodardj commented 6 years ago

Same. We just had a cert expire and it crashes the whole app. Pretty bad failure mode.

flovilmart commented 6 years ago

And as mentioned many times, we won’t fix this one. This is inside the node APN module, feel free to open an issue there.