ostinelli / apnotic

A Ruby APNs HTTP/2 gem able to provide instant feedback.
MIT License
477 stars 95 forks source link

`Apnotic::Connection.development` modifies configuration hash unexpectedly #104

Closed davelyon closed 3 years ago

davelyon commented 3 years ago

When migrating some code to use connection pools, we discovered a confusing issue that caused pushes that were meant for the APNS production environment to be unexpectedly send to the development/sandbox environment.

After some digging, we determined that the issue was related to the .development method, as not using it would make the issue go away. We eventually determined that our because our configuration for the dev/prod connection pools via a module was using the same constant CONFIG as the basis for creating pooled connections, the call to merge! (mutating in-place) in development was causing any new connections in either pool to be created with the development URL by mistake.

Suggested Fix:

I believe the quickest fix here would be to change this line: https://github.com/ostinelli/apnotic/blob/master/lib/apnotic/connection.rb#L15 to look something like this:

# Original: options.merge!(url: APPLE_DEVELOPMENT_SERVER_URL)
{ url: APPLE_DEVELOPMENT_SERVER_URL }.merge(options)

I would be happy to submit a PR for that if that seems reasonable.

As a workaround, if anyone needs one temporarily:

Just use Connection.new( and pass url: 'https://api.sandbox.push.apple.com:443' as part of the options, rather than use .development

Thanks!

benubois commented 3 years ago

Hi @davelyon,

I'm happy to accept a pull-request.

Thanks!