Skip to content

Commit 2af4edf

Browse files
milan-zededaeriknordmark
authored andcommitted
wwan: Update metrics/status json files atomically
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 <[email protected]>
1 parent 5dd0c13 commit 2af4edf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/wwan/usr/bin/wwan-init.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,15 @@ __EOT__
442442
if [ "$EVENT" = "METRICS" ]; then
443443
json_struct \
444444
"$(json_attr networks "$(printf "%b" "$METRICS" | json_array)")" \
445-
| jq > "$METRICS_PATH"
445+
| jq > "${METRICS_PATH}.tmp"
446+
# update metrics atomically
447+
mv "${METRICS_PATH}.tmp" "${METRICS_PATH}"
446448
else
447449
json_struct \
448450
"$(json_attr networks "$(printf "%b" "$STATUS" | json_array)")" \
449451
"$(json_str_attr config-checksum "$CHECKSUM")" \
450-
| jq > "$STATUS_PATH"
452+
| jq > "${STATUS_PATH}.tmp"
453+
# update metrics atomically
454+
mv "${STATUS_PATH}.tmp" "${STATUS_PATH}"
451455
fi
452456
done

0 commit comments

Comments
 (0)