Swatto / promtotwilio

Send text messages for Prometheus alerts using Twilio
MIT License
33 stars 21 forks source link

Sending multiple requests in quick succession sends to same number #6

Closed prestonvanloon closed 4 years ago

prestonvanloon commented 4 years ago

If you send multiple requests quickly, they overwrite the options with the receiver.

Expected: Send three requests to send message with a receiver field different phone numbers. Messages are sent to three different numbers.

Observed behavior: the message is sent three times to same number.

Here is the offending code where the request shares / reuses the same options by copying the pointer to the options. https://github.com/Swatto/promtotwilio/blob/d63336cf34797f5634f7c72b1284a4af9a97d23e/options_with_handler.go#L54

The service needs a mutex around this option or make a deep copy of the options before mutating it.

prestonvanloon commented 4 years ago

Here's the simplest way to understand the problem: https://play.golang.org/p/rZyz-ivCnch

prestonvanloon commented 4 years ago

And here's a simple fix to that example: https://play.golang.org/p/_NLLKtaP0mv