ileitch/rapns — Issue #24: Infinite notification loop
Author: tompesman
Created: 2011-12-20 15:56:10+00:00
State: open

First of all, thanks for the rapns gem! I just experienced a strange behavior, after running flawlessly for over a week the following happend in the log. Initially it looks like the gem looses connection to the APN server and restores it successfully, but the connection is lost to the MYSQL server and not successfully restored. Therefore it fails to update the record to mark the notification it has been sent, but it somehow retreives the same record to be delivered, resulting in a notification sent every 2 seconds. :-)

```bash
[2011-12-20 15:53:58] [FeedbackReceiver] Connected to feedback.sandbox.push.apple.com:2196
[2011-12-20 15:54:59] [FeedbackReceiver] Connected to feedback.sandbox.push.apple.com:2196
[2011-12-20 15:56:00] [FeedbackReceiver] Connected to feedback.sandbox.push.apple.com:2196
[2011-12-20 15:56:04] [ERROR] [DeliveryHandler 1] Lost connection to gateway.sandbox.push.apple.com:2195 (Errno::EPIPE), reconnecting...
[2011-12-20 15:56:05] [DeliveryHandler 1] Connected to gateway.sandbox.push.apple.com:2195
[2011-12-20 15:56:06] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:06', `updated_at` = '2011-12-20 14:56:06', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
[2011-12-20 15:56:08] [ERROR] [DeliveryHandler 2] Lost connection to gateway.sandbox.push.apple.com:2195 (Errno::EPIPE), reconnecting...
[2011-12-20 15:56:09] [DeliveryHandler 2] Connected to gateway.sandbox.push.apple.com:2195
[2011-12-20 15:56:10] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:10', `updated_at` = '2011-12-20 14:56:10', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
[2011-12-20 15:56:12] [ERROR] [DeliveryHandler 0] Lost connection to gateway.sandbox.push.apple.com:2195 (Errno::EPIPE), reconnecting...
[2011-12-20 15:56:13] [DeliveryHandler 0] Connected to gateway.sandbox.push.apple.com:2195
[2011-12-20 15:56:14] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:14', `updated_at` = '2011-12-20 14:56:14', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
[2011-12-20 15:56:17] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:17', `updated_at` = '2011-12-20 14:56:17', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
[2011-12-20 15:56:19] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:19', `updated_at` = '2011-12-20 14:56:19', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
[2011-12-20 15:56:21] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:21', `updated_at` = '2011-12-20 14:56:21', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
[2011-12-20 15:56:23] [ERROR] ActiveRecord::StatementInvalid, Mysql2::Error: MySQL server has gone away: UPDATE `rapns_notifications` SET `delivered_at` = '2011-12-20 14:56:23', `updated_at` = '2011-12-20 14:56:23', `delivered` = 1 WHERE `rapns_notifications`.`id` = 86
```

Is it possible to force a reconnect to the database?

Regards,

Tom