twilio / twilio-go

A Go package for communicating with the Twilio API.
MIT License
271 stars 40 forks source link

503 responses from Twilio API cause a panic #229

Closed percivalalb closed 4 months ago

percivalalb commented 4 months ago

Issue Summary

On Feb 14th 2024 the following occurred https://status.twilio.com/incidents/dhb0hj0dm9qf during this time saw some 503's from the Twilio API. This manifested as the following error in our Golang service (see Expection/Log section) causing the code to panic.

Steps to Reproduce

  1. Make a call to the Twilio API using the rest client in this library.
  2. Somehow force it to respond with 503
  3. See that in panics.

Exception/Log

"error":"error decoding the response for an HTTP error code: 503: invalid character 'o' in literal null (expecting 'u')","errorVerbose":"invalid character 'o' in literal null (expecting 'u')\nerror decoding the response for an HTTP error code: 503\[ngithub.com/twilio/twilio-go/client.(*Client](http://ngithub.com/twilio/twilio-go/client.(*Client)).doWithErr\n\[tgithub.com/twilio/twilio-go@v1.16.1/client/client.go:81\ngithub.com/twilio/twilio-go/client.(*Client](http://tgithub.com/twilio/twilio-go@v1.16.1/client/client.go:81%5Cngithub.com/twilio/twilio-go/client.(*Client)).SendRequest\n\[tgithub.com/twilio/twilio-go@v1.16.1/client/client.go:139\ngithub.com/twilio/twilio-go/client.(*RequestHandler](http://tgithub.com/twilio/twilio-go@v1.16.1/client/client.go:139%5Cngithub.com/twilio/twilio-go/client.(*RequestHandler)).sendRequest\n\[tgithub.com/twilio/twilio-go@v1.16.1/client/request_handler.go:32\ngithub.com/twilio/twilio-go/client.(*RequestHandler](http://tgithub.com/twilio/twilio-go@v1.16.1/client/request_handler.go:32%5Cngithub.com/twilio/twilio-go/client.(*RequestHandler)).Get\n\[tgithub.com/twilio/twilio-go@v1.16.1/client/request_handler.go:91\ngithub.com/twilio/twilio-go/rest/api/v2010.(*ApiService](http://tgithub.com/twilio/twilio-go@v1.16.1/client/request_handler.go:91%5Cngithub.com/twilio/twilio-go/rest/api/v2010.(*ApiService)).FetchCall\n\[tgithub.com/twilio/twilio-go@v1.16.1/rest/api/v2010/accounts_calls.go:443](http://tgithub.com/twilio/twilio-go@v1.16.1/rest/api/v2010/accounts_calls.go:443)

Technical details:

kevinburkesegment commented 4 months ago

Apologies - here's the logic I see for sending a HTTP request and decoding it, which is the top of the stack trace that you provided.

    if res.StatusCode < 200 || res.StatusCode >= 400 {
        err = &TwilioRestError{}
        if decodeErr := json.NewDecoder(res.Body).Decode(err); decodeErr != nil {
            err = errors.Wrap(decodeErr, "error decoding the response for an HTTP error code: "+strconv.Itoa(res.StatusCode))
            return nil, err
        }

        return nil, err
    }

I see the error message in your response, but I don't see where this code could panic. Is it possible you can provide more of a stack trace or more details about what request was failing?

percivalalb commented 4 months ago

Hi Kevin,

I've just had a look at the stacktrace again and followed it back to an issue within my code base. I jumped the gun here, appreciate you putting time into looking though. Sorry for the false alarm!