ApplePushChannel not sending notifications #85

Closed
Matthewh66 opened this Issue Jan 24, 2013 · 76 comments

Projects

None yet
@Matthewh66

Hello,

Sorry to bother you again - another quick question if I may. I'm developing an app to submit message to apple.

In my PushServiceSettings I've set the MaxAutoScaleChannels to be 1. Occasionally, normally after a period of inactivity, when I try to send a message the push service fails to queue the notification (the notification never arrives and the SendSuccess or SendFailure event handlers never fire ). There is no exception rasied, and the ChannelDestroyed event has never fired either.

Do you know of any problem with setting MaxAutoScaleChannels = 1. All other settings are the default ones.

Kind regards
M

@Redth
Owner

Have you tried the latest version that was released yesterday (and another today)? 1.1.1.0

There were changes made to how Apple notifications are managed in this release. Please let me know after trying this release :)

@Matthewh66

Hi there,

I've tried the new release and unfortunately the problem is still occuring.

Every so often when I queue a message with the following code the message does not arrive on my phone and neither the OnNotificationSendFailure or OnNotificationSent fire. There are no other exceptions raised.

Push.QueueNotification(NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(messageText)
.WithSound("default")
.WithBadge(badgeCount)
.WithTag(messageDetails)
.WithCustomItem("cwID", customItem)
.WithCustomItem("mID", customItem2 )
);

I've currently got the MaxAutoScaleChannels set to 1 but I've also seen the same problem when set to 10. I'm struggling to know how to debug this or set about solving it.

Any help you can give would be much appreciated.

Regards,
M

@Matthewh66

Hi There,

I've also found examples where the SendSuccess event is firing more than once for the same notification. We are outputting to a log file at the point we queue each notifiction so are sure that we are only submitting it once.

Any idea what could be causing these two bugs?

Thank you

@Redth
Owner

I'd need to know more about your code. I've just tested things again myself, and I cannot replicate duplicating success events, or missing failed events...

@Matthewh66

Thanks for your reply.

We're currently running ten threads each with their own push service. We're going to reduce it down to a single thread to see if the problems disappear and rule out it being a thread safety issue. I'm also going to add some more logging to help see if the bug is in our code or not.

I'll get back to you early next week if that's ok.

Many thanks and kind regards. Have a great weekend :-)

@Redth
Owner

Sounds good... I don't think there's a chance of it being a thread safety issue as PushService is quite isolated from itself, but you never know. I'm pretty confident my queuing system is working quite well now, I'm unable to get it to miss sending or failing events for the messages I queue up :s

@Matthewh66

Switching to one thread has helped understand the issue much better.

When we queue a push notification after a long period of inactivity, neither the SendSuccess or SendFailure events fire.

The push notification then later sends ( and SendSuccess fires) at the point that we queue our next push ( which might be hours later).

Is there a call we can make to wake the channel up before we send after a period of inactivity?
Is there a set period in which the channel dies? We don't get the ChannelDestroyed event fired to indicate the channel has died.
Is there a way that we can test if the channel is awake before we queue a notification?
Is there a call we can make to flush any queued notifications without needing to queue a new notification?

Thanks again for your help
M

@Matthewh66 Matthewh66 closed this Jan 26, 2013
@Matthewh66 Matthewh66 reopened this Jan 26, 2013
@Redth
Owner

Thanks for debugging on this!

I will need to take a look to see why this is happening

Sounds like a bug as the channel should not sleep/close/die on its own ever!

@Redth
Owner

I think what may be happening is on Line 275 of ApplePushChannel.cs there is a check to see if the connection is connected still when looking at sent notifications and checking to see if we've waited long enough for them to be deemed as sent. If the connection is not connected, currently any sent notifications are not 'cleaned up', instead their sent time keeps getting bumped ahead. I've thought about why this check was originally put in a bit, and I think it was just an additional level of 'just in case'. I'm trying to think of a scenario where not having this included would cause issues, but I don't think it ever would. I think I will go ahead and remove this check.

@Redth Redth added a commit that referenced this issue Jan 27, 2013
@Redth Testing a fix for #85 efb665b
@Redth
Owner

@Matthewh66 try the latest master I just pushed. I added a change for the suspect line of code I'm hoping should fix your issue :)

@Matthewh66

Thanks Redth. I'll update my source base to the latest version and see if it resolves the issue. Thanks very much for looking at this so quickly.

@Matthewh66

Hi Redth,

I'm adding the DLLs into my solution using nuget. Is the change you've made included in version 1.1.1.0? If not where can I get the PushSharp.Apple dll with the modification from?

@Redth
Owner

There's no DLL updated yet for it... stay tuned.

@Matthewh66

Hi Redth,

Thanks for sending the link, I'm importing them into my solution now. Just so I'm clear, is this a fix for the channel sleeping issue or the requeue problem or both!)

Thanks

@Redth
Owner
@Matthewh66

Hi Redth,

Thanks, I've got a new service up running now which I'll leave overnight and try again in the morning. That will give the channels a chance to sleep (and me I hope :-)

Sorry, the requeing issue. When we queue a push notification after a long period of inactivity, neither the SendSuccess or SendFailure events fire. The push notification then later sends ( and SendSuccess fires) at the point that we queue our next push ( which might be hours later). Of course if the channel sleeping issue is fixed this won't be a problem. However we've got MaxNotificationsRequeues set to zero so wouldn't expect it to get requeued at all. Thought you might want to know this.

I'll update you in the morning. Thanks again.

Kind regards
M

@Redth
Owner
@Matthewh66

Hi Redth,

The service looks to be running well now :-)

We left it running overnight and all messages we've sent this morning have arrived and the SendSuccess event has fired once for all of them. Still early days but it looks positive at the moment. I'll update you later in the day as to how things are.

Thanks again.
M

@Matthewh66

Hi Redth,

Sorry, but it seems that the change has caused a different problem. About 1 in 10 of our notifications do not arrive but the SendSuccess event is firing. This is happening on pushChannels that have not been used for about 1.5 hours but not for those that have been used recently.

This is a worse problem for us in a way because we think we've sent when in fact we haven't. We are going to revert to the old DLL for the time being.

Any ideas as to why a 'stale' pushChannel might raise a sendSuccess event. I suspect that the issue is in the cleanup method but can't be sure.

Regards,
M

@Redth
Owner

Ok, I'll revert the change I made.

The only thing I can think of that's possible is somehow a message is sent, then the connection gets closed by Apple or some other network interruption (the message sent was OK in this case), and that message gets stuck in the 'sentNotifications' list. Since Cleanup only expires sentNotifications (once a sent notification is 'expired' it means it was assumed to be successfully delivered and SendSuccess event is then fired) when the connection is open, the message does not get expired. The connection is never reopened until a new notification is sent (because a call to Connect() never happens until messages are being sent).

If this actually what's happening, I might be able to occasionally call the Connect() method (even possibly from inside the Cleanup() method - or a separate timer) just to ensure the connection is open. I'm not sure yet if this will cause issues with the send method calling Connect() (eg: any race conditions) but it should be ok given that I do locking around this.

I'll make a change shortly and post some new binaries for your to try. Thanks for digging into this with me, and helping make the library better for everyone :)

@Matthewh66

Hi,

Thanks for your reply. I hope we aren't becoming a pain! We think the library is brilliant, and yes we would be delighted if we could help improve it in a small way.

I look forward to hearing from you.

M

@Redth Redth added a commit that referenced this issue Jan 29, 2013
@Redth Another test fix for #85 35b531d
@Redth
Owner

No pain at alll :) I'd much rather get things working as best as possible. It's very hard for me to test edge cases like this myself, so this is great.

@Matthewh66

Hi there,

Thanks so much for the new DLLs. I'm going to try them out tomorrow and will feedback on how I get on.

Regards
M

@Redth
Owner

Any updates?

@Matthewh66

Sorry,

Been distracted for a couple of days. Am working on it again now, so will update you later :-)

Thanks

@Matthewh66

Hi there,

Sorry, not good news :-( We are finding that the latest version has the same problem as the previous one.

Thought the below summary might help clarify how we are using the library:

 • We have a windows service running on our web server
 • The service has ten threads 
 • Each thread has it’s own PushService
 • Each PushService has a running apple service (no others at present though we plan to run a GCM one in     each thread in the near future)
 ○ These are the only settings we’ve changed from the default ones in our apple service:
    MaxAutoScaleChannels = 1
    MaxNotificationRequeues = 0     
 • Each thread poles our database looking for a message to send
 • If the thread finds a message to send it calls the push service to queue the message using the SendNotification  method
 • If the thread does not find a message it does not call the push service 
 • Therefore if there are no messages to send out, the a PushService's SendNotification method might not get called for long periods of time e.g. for hours at a time over night when traffic is light

These are the symptoms from the last two PushSharp.Apple dlls you sent us (you made two different changes to the clean up method in the ApplePushChannel.cs):

• If the push service remains inactive for about an hour the next time we call SendNotification  the SentSuccess event gets fired but the message does not get passed to apple
• If by chance the same thread picks up a message soon after, everything works as expected i.e. the channel is 'awake', the message gets sent and SendSuccess is raised
• The problem only appears when the push service is 'woken up' and asked to send a message

The original dlls we used from the site still had a 'sleeping' issue but the but the symptom then was that neither the success or fail event fired. Although undesirable this is preferable to sendSuccess being fired when the message has not been sent.

Not sure if any of this helps but wrote it down just in case there is something in there that sparks a thought!

Thanks again and let me know if there is anything I can do to assist.

Kind regards,
M

@Matthewh66

Hi there,

I've temporarily fixed this problem by checking to see if the each thread has been used in the last 30 mins. If it hasn't then I stop and start the apple service. I don't think this is ideal as I think apple would prefer us to keep the connection open indefinately. It does however fix the problem of channels not working properly after a period of inactivity (about 40 mins is the threshold)

Regards,
M

@Redth
Owner

Thanks for the update. I haven't had a lot of time the last week to dig into this one more, hoping to soon. I'll have to do a bit more searching to try and see what's going on. I'm quite surprised my latest test didn't work, or at least caused the same issues you were having, since it's a pretty unobtrusive fix... I wonder if something else has changed since the version you were using..

@Matthewh66

Hi,

No problem at all. We really appreciate anything you're able to do :-) .

@Redth
Owner

Can you confirm which version you are using now that has the issue? Is it the NuGet 1.1.0.0 release? I'm going to try and see if anything has changed since the release you are using to track this down without bringing in the issue of Success event firing but messages not actually being delivered.

@Matthewh66

Hi Redth. Yes we are currently using the NuGet 1.1.0.0 release.

The versions that were causing the non delivery but SendSuccess firing where both from versions you gave me direct links to. Hope this clarifies :-)

@Matthewh66

Hi there,

Just experienced the issue again despite the remedial steps i'm now taking of restarting the apple service if it hasn't been used for 30 mins.

 - No success or failure event raised despite calling QueueNotification
 - By chance the same thread picked up a second message soon after, which was sent as expected.  
 - It also sent the first message
 - In the meantime, because we hadn't marked the message as sent in our database (i.e. SendSuccess had not fired), a different 
   thread picked it up and sent it as well

If the thread had not been active again so soon after then the first message would not have been dispatched so quickly.

I can't understand how, despite calling the QueueNotification method, that a SendSuccess event isn't automatically raised after 3 seconds?

I appreciate that this is really difficult for you to 'unpick' so i'm going to try and create a sample project that demonstrates the issue for you :-). Wondered if that would help in anyway?

Kind regards,

@Redth
Owner

Yes, a sample project definitely could not hurt :)

The SendSuccess isn't automatically raised until the message has actually been written to the network stream. So it seems somehow this scenario had the message not written to the stream (somehow in limbo) so you never marked it as sent, so your process decided from the database it needed to be sent. It got queued again, which triggered the original one to be sent finally. I'm assuming eventually SendSuccess did fire for the original one, it just took much longer than expected. If this is how it all went down, at least it makes sense to me, except for why the message is getting stuck in the first place...

At this point I'm wondering if there's something causing it to get stuck at the ApplePushService level (and not get distributed out to the Channel).

@kgyokov

I think I might be experiencing the same issue.

Sometimes the code would queue 6 notifications to Apple (using 6 different device tokens) but none of the events would fire and the notifications would not reach any of the phones.

However, if the code queues another 6 notifications (within say 20 minutes), the OnNotificationSent event fires 12(!!!) times almost immediately and each phone gets the notification.

Below is the log. Sensitive information has been omitted. Maybe the thread numbers and timestamps would help you diagnose the problem.

/* 1 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b4b"),
  "timestamp" : ISODate("2013-02-20T01:04:18.64Z"),
  "level" : "DEBUG",
  "thread" : "25",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 2 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b4a"),
  "timestamp" : ISODate("2013-02-20T01:04:18.64Z"),
  "level" : "DEBUG",
  "thread" : "25",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 3 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b49"),
  "timestamp" : ISODate("2013-02-20T01:04:18.406Z"),
  "level" : "DEBUG",
  "thread" : "29",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 4 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b48"),
  "timestamp" : ISODate("2013-02-20T01:04:18.406Z"),
  "level" : "DEBUG",
  "thread" : "31",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 5 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b47"),
  "timestamp" : ISODate("2013-02-20T01:04:18.406Z"),
  "level" : "DEBUG",
  "thread" : "6",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 6 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b46"),
  "timestamp" : ISODate("2013-02-20T01:04:18.39Z"),
  "level" : "DEBUG",
  "thread" : "27",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 7 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b45"),
  "timestamp" : ISODate("2013-02-20T01:04:18.39Z"),
  "level" : "DEBUG",
  "thread" : "29",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 8 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b44"),
  "timestamp" : ISODate("2013-02-20T01:04:18.39Z"),
  "level" : "DEBUG",
  "thread" : "31",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 9 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b43"),
  "timestamp" : ISODate("2013-02-20T01:04:18.39Z"),
  "level" : "DEBUG",
  "thread" : "6",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 10 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b42"),
  "timestamp" : ISODate("2013-02-20T01:04:18.39Z"),
  "level" : "DEBUG",
  "thread" : "27",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 11 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b41"),
  "timestamp" : ISODate("2013-02-20T01:04:18.14Z"),
  "level" : "DEBUG",
  "thread" : "23",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}

/* 12 */
{
  "_id" : ObjectId("51242112e93b5d081cbf8b40"),
  "timestamp" : ISODate("2013-02-20T01:04:18.14Z"),
  "level" : "DEBUG",
  "thread" : "23",
  "message" : "Successfully sent Apple notification: ",
  "method" : "Events_OnNotificationSent",
}




/* 13 */
{
  "_id" : ObjectId("5124210ee93b5d081cbf8b3f"),
  "timestamp" : ISODate("2013-02-20T01:04:14.265Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token A",
}

/* 14 */
{
  "_id" : ObjectId("5124210ee93b5d081cbf8b3e"),
  "timestamp" : ISODate("2013-02-20T01:04:14.265Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token B",
}

/* 15 */
{
  "_id" : ObjectId("5124210ee93b5d081cbf8b3d"),
  "timestamp" : ISODate("2013-02-20T01:04:14.265Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token C",
}

/* 16 */
{
  "_id" : ObjectId("5124210ee93b5d081cbf8b3c"),
  "timestamp" : ISODate("2013-02-20T01:04:14.25Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token D",
}

/* 17 */
{
  "_id" : ObjectId("5124210ee93b5d081cbf8b3b"),
  "timestamp" : ISODate("2013-02-20T01:04:14.25Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token E",
}

/* 18 */
{
  "_id" : ObjectId("5124210ee93b5d081cbf8b3a"),
  "timestamp" : ISODate("2013-02-20T01:04:14.25Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token F",
}




/* 23 */
{
  "_id" : ObjectId("51241adce93b5d081cbf8b35"),
  "timestamp" : ISODate("2013-02-20T00:37:48Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token A",
}

/* 24 */
{
  "_id" : ObjectId("51241adce93b5d081cbf8b34"),
  "timestamp" : ISODate("2013-02-20T00:37:47.984Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token B",
}

/* 25 */
{
  "_id" : ObjectId("51241adbe93b5d081cbf8b33"),
  "timestamp" : ISODate("2013-02-20T00:37:47.984Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token C",
}

/* 26 */
{
  "_id" : ObjectId("51241adbe93b5d081cbf8b32"),
  "timestamp" : ISODate("2013-02-20T00:37:47.968Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token D",
}

/* 27 */
{
  "_id" : ObjectId("51241adbe93b5d081cbf8b31"),
  "timestamp" : ISODate("2013-02-20T00:37:47.968Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token E",
}

/* 28 */
{
  "_id" : ObjectId("51241adbe93b5d081cbf8b30"),
  "timestamp" : ISODate("2013-02-20T00:37:47.968Z"),
  "level" : "DEBUG",
  "thread" : "14",
  "message" : "Queuing Apple Notification using token F",
}
@sydwebdesign

Hi,

I experienced similar problem. PushSharp stops sending push notifications to Apple devices after sending random number of notifications.

I digged into this issue a little bit. It seems that in the "ApplePushChannel.cs" file, the code for requeuing notifications on failure could have an out-of-range exception (Line 256-264). It happens when the queue has only one notification and it fails. If I add a simple check before GetRange, the not-sending issue disappears. It seems the thread exits on that exception.

@janporu-san
@Redth
Owner

@janporu-san that's a function of Github! You'll have to unsubscribe from the notifications (unwatch the thread) on Github....

@kgyokov

We observed a peculiar scenario:

  1. After a long period of inactivity (e.g. > 3 hours), we queue a single notification. The notification goes out successfully and OnNotificationSent fires on thread number 6.
  2. A couple of minutes later, we queue a total of 6 notifications, one per phone. Only one phone receives this second notification and OnNotificationSent fires just once, on thread number 6.
  3. After a few more minutes, we again queue 6 notifications to different phones. This time every phone gets the notification. OnNotificationSent fires once on thread number 6 and twice on each of the other 5 threads.
@Redth
Owner

@kgyokov thanks for detailing your scenario.

I think I have a better understanding of how I can try and reproduce this issue now. I have a feeling that the ApplePushChannel is fine, and that perhaps the problem lies in the ApplePushService class instead (perhaps something's causing queued notifications not to be distributed to the ApplePushChannel instances).

If anyone is now intimately familiar enough with PushSharp and would like to test something for me, I'd suggest creating your own set of of ApplePushChannel instances... Perhaps just put them in a List, instantiate them all, and then queue notifications to each of them in order, moving to the next list index, and wrapping around to the 0 index after you hit the end (I think you get the point).

Testing this way could help narrow down where the problem is (eg: rule out ApplePushService or maybe the opposite, rule out ApplePushChannel, if you cannot recreate the issue this way).

If that makes sense to anyone, and you're willing to try, let me know!

@Redth Redth added a commit that referenced this issue Feb 28, 2013
@Redth Added more locking around channels
This might help #85
dd361ef
@Redth Redth added a commit that referenced this issue Mar 6, 2013
@Redth More work around #85 8926378
@dswigger

I am experiencing this issue and will be attempting some of these fixes. What I am experiencing is that I can queue a message when I first fire up my application and it will go out. Later on(will have to now try and measure the time) the onsent will fire but the notification will not be sent to the device. If I rapidly add more stuff to go out - eventually the notifications will be sent out. The notification tray on the ipad said one message had sat for 34 minutes.

I will post what I find.

@Matthewh66

Hi everyone,

I have been running some diagnostic tests. I am now sure that the problem is occurring because the TCP connection is being destroyed. I don't think pushsharp is coping after a period of inactivity because the channel has dropped it's TCP connection (i'm not sure at which end it is being destroyed, mine or Apple's.

What does anyone else think?

@Redth
Owner

Yeah this seems to be the case. From some debugging I've done, and another fellow has done, it seems like sometimes the connection gets closed, but the call to the stream.Write still succeeds for the first message. Now the question is, how do we determine this is happening...

I have a few ideas to try implementing:

  1. It looks like some others use the TCP KeepAlive socket option - grocer/grocer#10 This may help with long lived connections, and from what I can tell, can't hurt to add in.
  2. I can try polling the socket before sending notifications (eg: socket.Poll(0, SelectMode.SelectWrite); ). Not sure how much this would actually help, but seems like one of those cases of it can't hurt.
  3. One thought I had was that it seems the first .Write call is the only one that works when the connection is closed, and after that, the next ones fail as expected. I can't find any conclusive evidence, but there are some posts that allude to this being expected behaviour (that the OS is essentially buffering the first call, so the app thinks it succeeded, then by the next call it knows there's a problem with the connection). Anyway, my thinking is to break each message up into two separate .Write calls. I know every message must be at least X bytes long, so I could send the identifier, length, etc. byte data in the first .Write call, and the rest of the payload in the next. Again, no idea if this will actually help, but may be worth a try.

In any case, I'm really close to merging my ioc-v2 branch into master which will bring quite a few breaking changes to the API, and a lot of structural changes underneath. I'm eager to move to this because I think it may eliminate some other variables from these problems. The code is now unit testable, and in making it so, I had uncovered a number of issues, as well as simplified parts of it (for instance, each Push Channel no longer maintains its own queue - this really helps in gracefully stopping PushSharp).

If everyone's happy enough to move to this new version soon, I'd prefer to implement these changes on it. I'll post back here when I've done so and am happy that the branch is at a state worthy of being tested against this issue.

Thanks again all for your feedback, any additional comments about the ideas I've outlined are more than welcome!

@Redth Redth added a commit that referenced this issue Mar 15, 2013
@Redth Enhancements in connection handling for APNS
This relates to #85
Added keep alive option to the socket, now poll the socket for write
mode before sending, and also splits up the message writes into two
calls for each notification to try and cause a closed stream to throw an
exception
1fd125b
@Redth Redth was assigned Mar 15, 2013
@AndreasBlenk

Hey,
when will you release a new NuGet version? I have a problem with the current one: If i test it with only three Apple Notifications (1. Valid, 2. invalid, 3. valid) then it always hangs by calling "pushService.StopAllServices(true)".

Result:
1. sent, 2. not sent, 3. not sent.

The invalid one is a Development-Token while i am using a Production certificate. Also if i modify a valid Token by my self with a view digits it doesnt work and always hangs. If i use "12345" as invalid Token then it works.

Workaround:
I call for each single Push-Notification:

  • pushService.StartApplePushService(...) and
  • pushService.StopAllServices(true)" This works but i think this will me time intensiv for many notifications.

I think maybe it is solved since your last NuGet Release?

Thanks
Andreas

@Redth
Owner

@AndreasBlenk this is not a good idea, Apple does not like you to close the connection and open a new one for each notification. There is probably better working support since the latest NuGet release, however I'm not updating NuGet until 2.x is ready (from the ioc-v2 branch). This should happen sometime this week!

@AndreasBlenk

Thanks for your advice. As we are still on testing our solution so we do not run it productive for now. If you release the Version 2 sometime this week this is ok for me and i will change it back and hope my issue is solved.

@Redth Redth added a commit that referenced this issue Mar 19, 2013
@Redth Enhancements in connection handling for APNS
This relates to #85
Added keep alive option to the socket, now poll the socket for write
mode before sending, and also splits up the message writes into two
calls for each notification to try and cause a closed stream to throw an
exception
54015cd
@Redth
Owner

2.0 is finally out :) Could I have people give this a try?

@AndreasBlenk

Hello, i have tested my issue i posted before again it is ok now - my problem seems to be solved. Thanks! Great Job!

@Redth
Owner

I'm going to close this issue for now. If anyone's having problems on 2.0, please open a new issue for it!

@Redth Redth closed this Mar 22, 2013
@MagnusJohansson

Same issue here. I do a very simple sample, exact as the sample on the home page.

Notifications are most often 1) not sent (despite NotificationSent event occurs, no error event) or 2) they batch up in some strange way, after a while they all queue up and if I send a notification several minutes or hours later, the ones missing suddenly arrives.

@Matthewh66

Hi there,

I'm the one who opened this case originally! We too are still seeing the issues described by Magnus with version 2.0. I have created a windows service which hopefully demonstrates the problem happening. I'm going to send it to Redth to see if he can replicate the issue (I hope that's okay Redth!). What is the best way of getting this to you?

The problem only seems to occur for us when a channel has not been used for a while (I reckon about 40 mins or so). I suspect that it's being caused by the TCP connection being terminated on Apples PNS server. PushSharp is not handling this scenario well.

Other than this problem, we are delighted with the libraries and think they are great. We get around this problem by restarting the a push service if it hasn't been used for 30 minutes (I know this is not the recommended approach, but we have quite a bit of through put so it doesn't happen that often).

I'll post again soon with an update

Thanks

@Redth
Owner

@Matthewh66 post it on dropbox or something for me to grab by a URL.

Unfortunately I've still never been able to simulate this scenario...

It would be even more useful if you were able to create a unit test using the fake/mock'd APNS server to simulate this condition....

@sue09876

I installed the newest PushSharp beta version today(2.1.2) I'm trying to send a notification to iphone device.
In my test code OnNotificationRequeue event always fired after I exeute following code:

        var appleNotification = new  AppleNotification()
            .ForDeviceToken(deviceToken)
            .WithAlert("Hello world !")
            .WithSound("default")
            .WithCustomItem("incidentId", "1")
            .WithBadge(7);

        push.QueueNotification(appleNotification);

the error messageI got from e.RequeueCause.is:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

Is that because I use apple sendbox to send notification?

Does anyone has the same issue?
What's the solution could be?

Thanks.

@normanhh3
@Redth
Owner

@sue09876 really going to need a stack trace please...

@Redth Redth reopened this Aug 9, 2013
@sue09876

Redth, Message, StackTrace and Source returns same message
e.RequeueCause.StackTrace
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

e.RequeueCause.Message
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

e.RequeueCause.Source
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

@Redth
Owner

@sue09876 you're going to have to do some digging then since I can't reproduce this, and that message is definitely not enough for me to go on :s

@sue09876

Redth, thank you for you quick response.
I'm busy for something right now.
Do you know what's the exception type could be???
I guess I need more time to find out this issue.

Do you have any test code I can use to get more info?

Thanks

@Redth
Owner

@sue09876 more likely I'd need to see the code YOU are using.. I've never had this error before, so I'm not sure where to begin looking without a stack trace...

@sue09876

Redth,
here is the step through debug test output, I hope this will help, I'll post my test code next

'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.Core.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.Utilities.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.Measurement\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.Measurement.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.GenericTestAdapter.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.MSAppContainerAdapter.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.UnitTestFramework.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.OrderedTestAdapter.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.TmiAdapter.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Common\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Common.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.UnitTestFramework\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestTools.CppUnitTestFramework.ComInterfaces.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestTools.CppUnitTestFramework.CppUnitTestExtension.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.Composition\v4.0_4.0.0.0__b77a5c561934e089\System.ComponentModel.Composition.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\USERS\user1\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\11.0\EXTENSIONS\TDUI2NSA.J3B\NUnit.VisualStudio.TestAdapter.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\USERS\user1\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\11.0\EXTENSIONS\TDUI2NSA.J3B\nunit.core.interfaces.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\USERS\user1\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\11.0\EXTENSIONS\TDUI2NSA.J3B\nunit.util.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\USERS\user1\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\11.0\EXTENSIONS\TDUI2NSA.J3B\nunit.core.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\user1\AppData\Local\Temp\nunit20\ShadowCopyCache\8100_635116389158169415\Tests_247181134\assembly\dl3\40c94ecf\85599555_1e95ce01\PushSharp.Tests.dll', Symbols loaded.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\user1\AppData\Local\Temp\nunit20\ShadowCopyCache\8100_635116389158169415\Tests_247181134\assembly\dl3\f97b58be\16bd6668_8f94ce01\nunit.framework.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\msdia110typelib_clr0200.dll'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\user1\AppData\Local\Temp\nunit20\ShadowCopyCache\8100_635116389158169415\Tests_247181134\assembly\dl3\a570e49e\206e524e_cb94ce01\PushSharp.Core.dll', Symbols loaded.
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\user1\AppData\Local\Temp\nunit20\ShadowCopyCache\8100_635116389158169415\Tests_247181134\assembly\dl3\e29a0ac0\b034284f_cb94ce01\PushSharp.Apple.dll', Symbols loaded.
The thread '' (0x18a0) has exited with code 0 (0x0).
The thread '' (0x40b4) has exited with code 0 (0x0).
The thread '' (0x3abc) has exited with code 0 (0x0).
Step into: Stepping over non-user code 'NUnit.Core.Reflect.InvokeMethod'
Step into: Stepping over non-user code 'NUnit.Core.TestMethod.RunTestMethod'
Step into: Stepping over non-user code 'NUnit.Core.TestMethod.RunTestCase'
Step into: Stepping over non-user code 'NUnit.Core.TestMethod.RunTest'
Step into: Stepping over non-user code 'NUnit.Core.NUnitTestMethod.RunTest'
Step into: Stepping over non-user code 'NUnit.Core.TestMethod.RunRepeatedTest'
Step into: Stepping over non-user code 'NUnit.Core.TestMethod.RunTestInContext'
Step into: Stepping over non-user code 'NUnit.Core.TestMethod.Run'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunAllTests'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuite'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuiteInContext'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.Run'
'vstest.executionengine.x86.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\user1\AppData\Local\Temp\nunit20\ShadowCopyCache\8100_635116389158169415\Tests_247181134\assembly\dl3\19fa3899\3e2dc349_8b93ce01\Newtonsoft.Json.dll'
Step into: Stepping over non-user code 'NUnit.Core.TestFixture.Run'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunAllTests'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuite'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuiteInContext'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.Run'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunAllTests'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuite'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuiteInContext'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.Run'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunAllTests'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuite'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.RunSuiteInContext'
Step into: Stepping over non-user code 'NUnit.Core.TestSuite.Run'
Step into: Stepping over non-user code 'NUnit.Core.SimpleTestRunner.Run'
Step into: Stepping over non-user code 'NUnit.Core.TestRunnerThread.TestRunnerThreadProc'
Step into: Stepping over non-user code 'System.Threading.ExecutionContext.RunInternal'
The thread 'EventPumpThread' (0x358c) has exited with code 0 (0x0).
The thread 'TestRunnerThread' (0x41b4) has exited with code 0 (0x0).
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
A first chance exception of type 'PushSharp.Apple.ConnectionFailureException' occurred in PushSharp.Apple.dll
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in PushSharp.Apple.dll
The thread '' (0x3a1c) has exited with code 0 (0x0).
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in PushSharp.Tests.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in PushSharp.Tests.dll but was not handled in user code
Step into: Stepping over non-user code 'System.Threading.Tasks.Task.Execute'
The thread '' (0x43cc) has exited with code 0 (0x0).
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionvstest.executionengine.x86.exeSystem.Threading.ThreadAbortException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Thread was being aborted. at NUnit.Util.DomainManager.DomainUnloader.UnloadOnThread()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()System.Threading.ThreadAbortException: Thread was being aborted.
at NUnit.Util.DomainManager.DomainUnloader.UnloadOnThread()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionvstest.executionengine.x86.exeSystem.AppDomainUnloadedException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Attempted to access an unloaded AppDomain.
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionvstest.executionengine.x86.exeSystem.AppDomainUnloadedException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Attempted to access an unloaded AppDomain.
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
Step into: Stepping over non-user code 'System.Threading.ExecutionContext.RunInternal'
Step into: Stepping over non-user code 'System.Threading.Tasks.Task.ExecuteWithThreadLocal'
Step into: Stepping over non-user code 'System.Threading.ExecutionContext.RunInternal'
The thread '' (0x26dc) has exited with code 0 (0x0).
The thread '' (0x345c) has exited with code 0 (0x0).
The program '[8100] vstest.executionengine.x86.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

@sue09876

Here is the test code I got from online and changed a little bit

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PushSharp.Apple;
using PushSharp.Core;
using PushSharp;
using System.IO;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using System.Globalization;

namespace PushSharp.UnitTests
{
[TestFixture]
public class PushSharpTests
{

    [Test]
    public void PushSharp_testApplePush()
    {
        var push = CreatePushBroker();

        var deviceToken = "an-valid-iphone-token-string";
        deviceToken = Regex.Replace(deviceToken, @"[<> ]", String.Empty);

        var appleNotification = new AppleNotification()
            .ForDeviceToken(deviceToken)
            .WithAlert("Hello world!")
            .WithSound("default")
            .WithCustomItem("incidentId", "1")
            .WithBadge(7);

        push.QueueNotification(appleNotification);

        Assert.IsTrue(appleNotification.Payload != null);
    }

    /// <summary>
    /// Creates APNS server wrapper.
    /// </summary>
    /// <returns></returns>
    private PushBroker CreatePushBroker()
    {
        PushBroker push;
        try
        {
            push = new PushBroker();
            push.OnDeviceSubscriptionExpired += PushOnDeviceSubscriptionExpired;
            push.OnNotificationSent += PushOnNotificationSent;
            push.OnNotificationFailed += PushOnNotificationFailed;
            push.OnNotificationRequeue += PushOnNotificationRequeue;

            //var appleCert = Resources.aps_production;
            var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../../Resources/PushSharp.Apns.Sandbox.p12"));

            var channelSettings = new ApplePushChannelSettings(false, appleCert, "pushsharp", true);


            channelSettings.FeedbackIntervalMinutes = 0;

            push.RegisterAppleService(channelSettings);
        }
        catch (Exception ex)
        {


            push = null;
            throw ex;
        }

        return push;
    }

    /// <summary>
    /// Gets the list of unsubscribed devices from feedback service.
    /// </summary>
    /// <param name="push"></param>
    private void CheckForUnsubscribedDevices(PushBroker push)
    {
        try
        {
            var registers = push.GetRegistrations<AppleNotification>();
            var applePushService = registers != null ? registers.FirstOrDefault() as ApplePushService : null;
            if (applePushService != null)
            {
                //applePushService.RunFeedbackService();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    /// <summary>
    /// Notification has been requeued
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="notification"></param>
    private void PushOnNotificationRequeue(object sender, NotificationRequeueEventArgs notification)
    {

        var message = notification.Notification as AppleNotification;
        var ex = notification.RequeueCause;
        if (ex is NotificationFailureException)
        {
            var error = ex as NotificationFailureException;
            throw error;
        }
        throw ex;
    }

    /// <summary>
    /// Notification has been sent successfully.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="notification"></param>
    private void PushOnNotificationSent(object sender, INotification notification)
    {
        var i = 0;
        //var message = notification.Tag as AppleNotification;
        var message = notification.Tag as AppleNotification;

    }

    /// <summary>
    /// We have failed to send notification.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="notification"></param>
    /// <param name="error"></param>
    private void PushOnNotificationFailed(object sender, INotification notification, Exception error)
    {
        //var message = notification.Tag as DeviceNotification;
        var message = notification.Tag as AppleNotification;
        if (error is NotificationFailureException)
        {
            throw error;
        }
        else
        {
            throw error;
        }
    }

    /// <summary>
    /// The application has been deleted from iPad and we received subscription expired event.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="expiredSubscriptionId"></param>
    /// <param name="expirationDateUtc"></param>
    /// <param name="notification"></param>
    private void PushOnDeviceSubscriptionExpired(object sender, string expiredSubscriptionId,
                                                 DateTime expirationDateUtc, INotification notification)
    {
        //if (notification != null && notification.Tag != null && notification.Tag is DeviceNotification)
        if (notification != null && notification.Tag != null && notification.Tag is AppleNotification)
        {
            var message = notification.Tag as AppleNotification;
        }

    }
}

}

@Redth Redth closed this Nov 28, 2013
@shaungl

Hi @Redth, @Matthewh66,

We are seeing this issue as well. GCM seems to be fine but iOS is very intermittent. The inactivity time can be as short as 5 minutes, then then usually the first push isn't received but subsequent ones are received. Sometimes we 3 or 4 could get lost before one is received successfully. All the while, we always receive the "Successfully sent" event. Any ideas?

@YARG

Yeah I'm getting that as well on an Azure setup. When you fire everything up it's fine and you can bang out notifications but if it doesn't get any for a while (I haven't worked out what 'a while' is yet) you have to send 3 or 4 notifications to wake the lot up again. Once you've done that it works .. until it goes back to sleep again due to no notification activity. We're using the NuGet version 2.0.4.0

@shaungl
@YARG

Thanks Shaung, I'm just installing it now funny enough. Good to hear from you again. I hope all's well!

@YARG

Shaung, I've just given it a quick test and deploying the cloud service now, hopefully it will do the trick. I'll post the results tomorrow as I've had a few long days recently and I need a beer! :-)

@shaungl
@YARG

Hi Shaung, many thanks.

Yep I've had some great results with the current Beta version, I've been running tests all day and it seems solid (fingers crossed). Great work Redth! I did a delay of 5 hours, sent a notification and it appeared fine ;-) Great!

Cheers guys.
Steve

@sharat

Guys I am totally dumbstruck.I am running 2.0.4.0 but seems the issue is not fixed. Which version I should give it a try?

@YARG

Hi Sharat, I just pulled in the latest Beta version from GitHub and that fixed the problem, which 2.0.4.0 has. I've been running it now for over a month and it seems fine. :-)

@sharat

@YARG thank you so much for your help. We lost almost 3 days behind this. Let's me pull the latest version.

@Jeevanjosh

I want to send Push Notifications to Apple IPhone , from my website , I am using Framework 3.5 how to get PushSharp.Core.dll for 3.5 framework ?

@perlasivakrishna

Hi Redth..
i am still facing the problem with old files. i am not able see the files in this link ( https://dl.dropbox.com/u/56106/PushSharp-Preview-20130128-0933.zip ) can you please send me 3.0 version PushSharp.dll files.
Thanks in advance.

@Redth
Owner

3.0 releases are available as pre-release packages on Nuget.org.

@ABSingl

Hi Redth..
I am using Pushsharp 4.0.10 and using the Apple production certificate to push notifications , what is happening notification is received sometimes and sometimes it missed to reach to production device.
Everything is verified that is we are using Apple production ceritificate, device token are from production environment. Can you please let me know reason behind missing of notifications some time.
Though when we tested on development server it works fine with no notification missed.
Here is my code.
Thanks in advance

public void PushBroker(ApnsConfiguration config, string notMessage, int notId, string deviceToken)
{
#region PushBroker
var apnsBroker = new ApnsServiceBroker(config);
// Create a new broker

        // Wire up events
        apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
        {

            aggregateEx.Handle(ex =>
            {

                // See what kind of exception it was to further diagnose
                if (ex is ApnsNotificationException)
                {


                }
                else {

                }

                // Mark it as handled
                return true;
            });
        };

        apnsBroker.OnNotificationSucceeded += (notification) =>
        {

        };

        // Start the broker
        apnsBroker.Start();
        string appleJsonFormat = "{\"aps\": {\"alert\":" + '"' + notMessage + '"' + ",\"sound\": \"default\"}}";

        apnsBroker.QueueNotification(new ApnsNotification
        {
            DeviceToken = deviceToken,
            Payload = JObject.Parse(appleJsonFormat)
        });


        // Stop the broker, wait for it to finish   
        // This isn't done after every message, but after you're
        // done with the broker
        apnsBroker.Stop();
        #endregion PushBroker
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment