Bad encoding for healthchecks payload results in HTTP 500 Server Error #260

Closed
opened 2019-11-28 14:10:28 +00:00 by mwalbeck · 5 comments

Thanks a lot for this project, it's fantastic.

What I'm trying to do and why

I've noticed that my backup where sometimes failing according to healthchecks, but the logs showed everything working. The logs also showed both the start and end ping being sent but only the start ping was registered by healthchecks.

I then realized that whenever there were files with non-standard characters in the filename, the end healthcheck with the payload, wouldn't arrive.

I frequently have files with æ, å or ø in the filenames.

Steps to reproduce (if a bug)

Send a POST request to healthchecks with requests library, where the data is a non standard character.

requests.post("HEALTHCHECKS_URL", data="å")

Actual behavior (if a bug)

Results in a HTTP 500 Server error from healthchecks, which results in the ping not going through and the check failing after the grace period.

Expected behavior (if a bug)

Healthchecks should be pinged, and the status code of the response should be HTTP 200.

Other notes / implementation ideas

All backups are run as normal, only the healthcheck fails.

This can be fixed by encoding the data payload as UTF-8 before sending it. If we make the following post request it goes through.

requests.post("HEALTHCHECKS_URL", data="å".encode("utf-8"))

Environment

borgmatic version: 1.4.15

borgmatic installation method: pip

Borg version: 1.1.9

Python version: 3.7.3

operating system and version: Debian 10

Thanks a lot for this project, it's fantastic. #### What I'm trying to do and why I've noticed that my backup where sometimes failing according to healthchecks, but the logs showed everything working. The logs also showed both the start and end ping being sent but only the start ping was registered by healthchecks. I then realized that whenever there were files with non-standard characters in the filename, the end healthcheck with the payload, wouldn't arrive. I frequently have files with æ, å or ø in the filenames. #### Steps to reproduce (if a bug) Send a POST request to healthchecks with requests library, where the data is a non standard character. requests.post("HEALTHCHECKS_URL", data="å") #### Actual behavior (if a bug) Results in a HTTP 500 Server error from healthchecks, which results in the ping not going through and the check failing after the grace period. #### Expected behavior (if a bug) Healthchecks should be pinged, and the status code of the response should be HTTP 200. #### Other notes / implementation ideas All backups are run as normal, only the healthcheck fails. This can be fixed by encoding the data payload as UTF-8 before sending it. If we make the following post request it goes through. requests.post("HEALTHCHECKS_URL", data="å".encode("utf-8")) #### Environment **borgmatic version:** 1.4.15 **borgmatic installation method:** pip **Borg version:** 1.1.9 **Python version:** 3.7.3 **operating system and version:** Debian 10
Owner

Thank you so much for reporting this! What an embarrassing bug. 😄 I'll have to audit the other monitoring integrations for similar unicode issues.

Thank you so much for reporting this! What an embarrassing bug. :smile: I'll have to audit the other monitoring integrations for similar unicode issues.
witten added the
bug
label 2019-11-28 18:08:47 +00:00
Author

Character encoding just quickly becomes confusing when we don't all use unicode. From what I can see it's caused by the requests library, which is using latin1 encoding by default, when you pass it a string. There is an issue relating to this on github. Technically passing a string directly isn't supported, but one should encode the string before sending. The main problem is that it isn't properly documented and even though it's not intended, it's still allowed, and it works most of the time.

Here is the issue if you are curious, https://github.com/psf/requests/issues/4503

Character encoding just quickly becomes confusing when we don't all use unicode. From what I can see it's caused by the requests library, which is using latin1 encoding by default, when you pass it a string. There is an issue relating to this on github. Technically passing a string directly isn't supported, but one should encode the string before sending. The main problem is that it isn't properly documented and even though it's not intended, it's still allowed, and it works most of the time. Here is the issue if you are curious, https://github.com/psf/requests/issues/4503
Owner

I appreciate the background. Looks like Healthchecks has "fixed" their 500 for the reproduction steps since you first posted it. But non-UTF-8-encoded text just shows up now as "[binary data]" in the UI instead of causing a 500 or appearing correctly as the original payload text. So I'll still be making the encoding fix as you suggested.

I appreciate the background. Looks like Healthchecks has "fixed" their 500 for the reproduction steps since you first posted it. But non-UTF-8-encoded text just shows up now as "[binary data]" in the UI instead of causing a 500 or appearing correctly as the original payload text. So I'll still be making the encoding fix as you suggested.
Owner

Fixed in borgmatic 1.4.16, just released. Thanks again for reporting this!

Fixed in borgmatic 1.4.16, just released. Thanks again for reporting this!
Author

I just updated, It works perfectly. Thank you, your work is greatly appreciated.

I just updated, It works perfectly. Thank you, your work is greatly appreciated.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#260
No description provided.