Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APNS expects expiration time to be in seconds, not MS. #14

Merged
merged 1 commit into from
Apr 7, 2016

Conversation

0x18B2EE
Copy link

@0x18B2EE 0x18B2EE commented Apr 7, 2016

parse-server expresses epoch time in milliseconds, while APNS expects it to be in seconds.
This causes parse-server (when correctly configured to send to APNS) to crash when the following cloud code is executed:

Parse.Cloud.define("testPush", function(request, response) {
    var query = new Parse.Query(Parse.Installation);
    query.equalTo( <query...> );

    var today = new Date();
    var timeout = new Date(today.getFullYear(), today.getMonth(), today.getDay() + 1);

    Parse.Push.send({
        where: query,
        expiration_time: timeout,
        data: {alert: "push hello"},
    }, {
        useMasterKey: true,
        success: response.success,
        error: response.error,
    });
});

with the error:

verbose: sending push to 69 installations
verb parse-server-push-adapter APNS APNS Connection 0 Connected
verb parse-server-push-adapter APNS APNS Connection 1 Connected
/parse-server/node_modules/parse-server/lib/ParseServer.js:333
            throw err;
            ^

TypeError: value is out of bounds
    at checkInt (buffer.js:971:11)
    at Buffer.writeUInt32BE (buffer.js:1064:5)
    at Connection.transmitNotification (/parse-server/node_modules/apn/lib/connection.js:691:8)
    at Connection.serviceBuffer (/parse-server/node_modules/apn/lib/connection.js:330:13)
    at Connection.<anonymous> (/parse-server/node_modules/apn/lib/connection.js:287:8)
    at Promise.apply (/parse-server/node_modules/q/q.js:1165:26)
    at Promise.promise.promiseDispatch (/parse-server/node_modules/q/q.js:788:41)
    at /parse-server/node_modules/q/q.js:1391:14
    at runSingle (/parse-server/node_modules/q/q.js:137:13)
    at flush (/Users parse-server/node_modules/q/q.js:125:13)

npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/Cellar/node/5.10.0/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.10.0
npm ERR! npm  v3.8.3
npm ERR! code ELIFECYCLE
npm ERR! parse-server@0.1.0 start: `node index.js`
npm ERR! Exit status 7
npm ERR! 
npm ERR! Failed at the parse-server@0.1.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the parse-server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs parse-server
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls parse-server
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /parse-server/npm-debug.log

This patch converts the time sent to APNS from MS to seconds.

@codecov-io
Copy link

Current coverage is 87.02%

Merging #14 into master will not affect coverage as of 14fe7b8

@@            master     #14   diff @@
======================================
  Files            5       5       
  Stmts          239     239       
  Branches        38      38       
  Methods          0       0       
======================================
  Hit            208     208       
  Partial          1       1       
  Missed          30      30       

Review entire Coverage Diff as of 14fe7b8

Powered by Codecov. Updated on successful CI builds.

@flovilmart
Copy link
Contributor

Very nice! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants