Comment 13 for bug 1841182

Revision history for this message
Emanuele Esposito (esposem) wrote :

The BZ is now public. However, there is only one suggestion that is private that might help solving the problem, so I am pasting it here:

```
Firstly, IMO, empty '/var/lib/cloud/data/set-hostname' is indeed an exception/case that cloud-init should handle properly than leave the service failed directly.

Back to this issue, hard reboot during boot or trigger sysrq b immediately when system boot up. The content of set-hostname lost after system boot up.
It seems that the content did not synced to disk when system reset.

Here is the instructions of sysrq b.

``b`` Will immediately reboot the system without syncing or unmounting
            your disks.

Below information shows that set-hostname already has content before reset, but it is 0 after boot again.
2022-11-08 01:49:17,759 - util.py[DEBUG]: Reading from /var/lib/cloud/data/set-hostname (quiet=False)
2022-11-08 01:49:17,759 - util.py[DEBUG]: Read 88 bytes from /var/lib/cloud/data/set-hostname
2022-11-08 01:49:17,759 - cc_set_hostname.py[DEBUG]: No hostname changes. Skipping set-hostname
2022-11-08 02:33:58,585 - util.py[DEBUG]: Reading from /var/lib/cloud/data/set-hostname (quiet=False)
2022-11-08 02:33:58,585 - util.py[DEBUG]: Read 0 bytes from /var/lib/cloud/data/set-hostname

Not sure if turn off buffering is helpful to mitigate this, but I did not reproduce this issue after 10+ retry times.

# diff -u /usr/lib/python3.9/site-packages/cloudinit/atomic_helper.py /usr/lib/python3.9/site-packages/cloudinit/atomic_helper.py.orig
--- /usr/lib/python3.9/site-packages/cloudinit/atomic_helper.py 2022-11-08 08:17:56.262679073 +0000
+++ /usr/lib/python3.9/site-packages/cloudinit/atomic_helper.py.orig 2022-11-08 08:17:03.722890860 +0000
@@ -25,7 +25,7 @@
     tf = None
     try:
         tf = tempfile.NamedTemporaryFile(
- dir=os.path.dirname(filename), delete=False, mode=omode, buffering=0
+ dir=os.path.dirname(filename), delete=False, mode=omode
         )
```