Bad encoding for healthchecks payload results in HTTP 500 Server Error #260
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#260
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
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.
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
Thank you so much for reporting this! What an embarrassing bug. 😄 I'll have to audit the other monitoring integrations for similar unicode issues.
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
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.
Fixed in borgmatic 1.4.16, just released. Thanks again for reporting this!
I just updated, It works perfectly. Thank you, your work is greatly appreciated.