sideshow / apns2

⚡ HTTP/2 Apple Push Notification Service (APNs) push provider for Go — Send push notifications to iOS, tvOS, Safari and OSX apps, using the APNs HTTP/2 protocol.
MIT License
3.01k stars 335 forks source link

Production()/Development() is not thread-safe (and more generally ClientManager will have inconsistent results if switching between Development/Production) #95

Closed froodian closed 7 years ago

froodian commented 7 years ago
  1. go version go1.8.3
  2. darwin/amd64
  3. Called client.Production() / client.Development() on clients return from ClientManager.Get
  4. Expected no data race
  5. Had "data race detected" from a test, between the line in my code calling client.Production() and apns2/client.go:156 (url := fmt.Sprintf("%v/3/device/%v", c.Host, n.DeviceToken))
froodian commented 7 years ago

I solved this by just keeping a ClientManager full of production clients and a ClientManager full of development clients, I feel like that's a fine solution and removes the ambiguity if another thread is sending on the client when you try to switch gateways, so I feel like that's a good answer to this, closing. Sorry about the noise.