snap logs dies on journald binary MESSAGE data
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
snapd |
Fix Released
|
Low
|
Ian Johnson |
Bug Description
Sometimes we get messages from journald's json format that is formatted like:
{ "__CURSOR" : "s=a2c27451c4d6
which then snapd fails to decode because we simplistically define systemd.Log as a map[string]string and we can't decode the array of integers for MESSAGE as a string, producing the following error in the daemon:
Aug 27 10:49:49 host snapd[9577]: response.go:365: cannot stream response; problem reading: json: cannot unmarshal array into Go value of type string
We should handle this better. It's slightly complicated because there's also this bit from the manpage:
> Journal entries permit non-unique fields within the same log entry. JSON does not allow non-unique fields within objects. Due to this, if a non-unique field is encountered a JSON array is used as field value, listing all field values as elements.
which implies that we not only have to worry about sometimes strings showing up as arrays of integers, but also non-unique keys in the original journald message showing up as a single string to an array of values.
Ideally someone should look at journald source code to figure out what all we need to handle, from snapd's source code we currently only really care about:
* __REALTIME_
* _PID
* SYSLOG_IDENTIFIER
* SYSLOG_PID
* MESSAGE
with the first two keys being "trusted" by systemd, so it seems unlikely those could ever be not a string, but the other three could be arbitrary from an app, so we need to have better handling there.
PR up: https:/ /github. com/snapcore/ snapd/pull/ 9234
the PR may be too naive, but it was what I could throw together quickly so we'll see how it does