cannot unmarshal state entry for "timings"
Bug #1843683 reported by
Zygmunt Krynicki
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
snapd |
Confirmed
|
Medium
|
Paweł Stołowski |
Bug Description
While reviewing test failures on master I ran across this error:
error: cannot get timings of change 6: could not get timings data from the
state: internal error: could not unmarshal state entry "timings": json:
cannot unmarshal number 4.39e+08 into Go struct field
This was on google:
Changed in snapd: | |
assignee: | nobody → Paweł Stołowski (stolowski) |
importance: | Undecided → High |
Changed in snapd: | |
status: | Confirmed → In Progress |
Changed in snapd: | |
importance: | High → Medium |
To post a comment you must log in.
Very interesting and bizzare problem. I couldn't reproduce it by running this spread test a 100 of times. The only way to reproduce it programatically in a unit test was to hand-craft state JSON to have such notation for the duration field. Injecting such value via mocked duration helper (even with saving and the restoring state) didn't reproduce it as for some reason json marshaller simply decided to encode it as 439000000. The fact that we hit this randomly means that the encoding is not fully deterministic and sometimes may use scientific notation.
Now, if such value is encountered when unmarshalling, the only way to succesfully unmarshall it to predefined structs is to use floats internally (float64). Decoding with UseNumber flag (e.g. with our DecodeWithNumber() that does that) doesn't help. While changing time.Duration (int64 really) to float64 for the duration field can be made in a backwards- compatible way, I fear the same can happen to doing/undoing fields which also use time.Duration, and that makes the scope of a potential fix bigger.