-
Notifications
You must be signed in to change notification settings - Fork 686
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
TypeError: Cannot read property 'authorized' of undefined #9
Comments
Thanks for highlighting this, I was always a bit suspicious of my use of self.socket.pair.on(), its looks like maybe I should use the callback on tls.connect which I somehow missed when I ported to 0.4, I shall investigate and get it fixed ASAP. |
Thanks Argon! Sounds like the right approach. I'd be more than happy to help with the fix or testing the fix. Just let me know. |
Well, I should be using the callback on tls.connect() but that is not the problem. The error is within the callback and for some reason self.socket is undefined so the property authorized cannot be read. Maybe the object is getting destroyed when it cannot connect but further investigation is required. |
I have been unable to replicate the problem and I can't quite figure out what could be causing the problem. Are you able to provide any example to reliably replicate the problem? |
I have finally found a fairly reliable way to reproduce by forcing multiple InvalidToken error conditions when sending a push notification (I think my original assumption that it was related to an apn service connection error is wrong). In my case, the token is actually a developer profile token being sent to the production gateway, but I presume it'll work for any invalid token. I believe the error occurs in other "valid" cases but haven't confirmed yet. Will do when I find another case. |
In my development environment, I get a different exception but along the same lines: assert.js:81 Haven't quite grasped why the path is different. I simply force two InvalidToken (8) errors in a row to generate this. |
OK. Scratch that last comment... I updated to the latest version of node (v4.11) and I'm back to the same exception: /Users/dgthistle/local/node/lib/node_modules/apn/lib/apn.js:50 The exception in the last comment was related to nodejs/node-v0.x-archive#1069 and was fixed with an upgrade. |
Assuming this only happens when the access token is invalid, I'll submit a pull request that just ignores the situation. If I see it occurring in other circumstances I'll let you know. |
The fact that it happens when the access code is invalid is interesting, I am currently running through the code to find the possible problem. |
I have succeeded in replicating the problem. WIth device token being incorrect. var device = new APNService.device(token);
var alert = "Message received from node-apn!";
var note = new APNService.notification();
note.alert = alert;
note.badge = 1;
note.device = device;
var note2 = new APNService.notification();
note2.alert = alert;
note2.device = device;
try {
service.sendNotification(note);
service.sendNotification(note2);
}
catch (e) {
console.log(e);
} |
I have pushed a patch to the 'develop' branch for this issue. Would you mind checking it out to ensure it fixes the problem at your end? |
Fix: http2session.shutdown() is not a function
I'm seeing this error periodically:
/usr/local/lib/node_modules/apn/lib/apn.js:50
self.socket.pair.on('secure', function () { if(!self.socket.authorized) { th
^
TypeError: Cannot read property 'authorized' of undefined
at SecurePair. (/usr/local/lib/node_modules/apn/lib/apn.js:50:62)
at SecurePair.emit (events.js:81:20)
at SecurePair._maybeInitFinished (tls.js:581:10)
at CleartextStream._pull (tls.js:350:15)
at SecurePair._cycle (tls.js:548:20)
at EncryptedStream.write (tls.js:94:13)
at Socket.ondata (stream.js:36:26)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:673:14)
at IOWatcher.onReadable as callback
I believe this occurs when the APN gateway is unreachable and the fix is to simply check the socket.
The offline cache will get populated and the note sent later.
The text was updated successfully, but these errors were encountered: