teslamotors / ansible_puller

Ansible daemon for massively-scaleable Ansible
MIT License
125 stars 33 forks source link

Handle `http.Client.Do` error properly to avoid segfaults. #35

Closed shk3 closed 1 year ago

shk3 commented 1 year ago

If the endpoint is unresponsive due to an outage, http.Client.Do can yield error. We must handle this error, or we would access an undefined response and traps segfault and crashes the daemon.

This PR also adds a test to catch this situation.

An error is returned if caused by client policy (such as CheckRedirect), or failure to speak HTTP (such as a network connectivity problem). A non-2xx status code doesn't cause an error. https://pkg.go.dev/net/http#Client.Do