Skip to content

Commit

Permalink
wwan: Update metrics/status json files atomically
Browse files Browse the repository at this point in the history
We get plenty of "Failed to unmarshall ..." errors from `devicenetwork/wwan.go`.
Note that nim is now using fsnotify to watch for updates of wwan
status and metrics, which are published from the wwan service as json files.
But because the wwan status and metrics json files are being updated
in-place, this sometimes produces several WRITE notifications
(one for each `write()` syscall), already before an update is
completely written out.
As a workaround, updates of wwan status and metrics are first
written into temporary files and then moved (renamed) atomically
into the proper filesystem locations, thus producing only a single
notification per file at the end of each update.

Signed-off-by: Milan Lenco <milan@zededa.com>
(cherry picked from commit 2af4edf)
  • Loading branch information
milan-zededa authored and eriknordmark committed Oct 29, 2021
1 parent 16de0d8 commit 3b7eb50
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/wwan/usr/bin/wwan-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,15 @@ __EOT__
if [ "$EVENT" = "METRICS" ]; then
json_struct \
"$(json_attr networks "$(printf "%b" "$METRICS" | json_array)")" \
| jq > "$METRICS_PATH"
| jq > "${METRICS_PATH}.tmp"
# update metrics atomically
mv "${METRICS_PATH}.tmp" "${METRICS_PATH}"
else
json_struct \
"$(json_attr networks "$(printf "%b" "$STATUS" | json_array)")" \
"$(json_str_attr config-checksum "$CHECKSUM")" \
| jq > "$STATUS_PATH"
| jq > "${STATUS_PATH}.tmp"
# update metrics atomically
mv "${STATUS_PATH}.tmp" "${STATUS_PATH}"
fi
done

0 comments on commit 3b7eb50

Please sign in to comment.