consul-template icon indicating copy to clipboard operation
consul-template copied to clipboard

AtomicWrite creates a new file not preserving the inode of the config file

Open phenixrizen opened this issue 5 years ago • 5 comments

Please note that the Consul Template issue tracker is reserved for bug reports and enhancements. For general usage questions, please use the Consul Community Portal or the Consul mailing list:

https://discuss.hashicorp.com/c/consul
https://groups.google.com/forum/#!forum/consul-tool

Please try to simplify the issue as much as possible and include all the details to replicate it. The shorter and simpler the bug is to reproduce the quicker it can be addressed. Thanks.

Consul Template version

consul-template v0.19.4 (68b1da2)

Configuration

not applicable

Command

consul-template -config=myconfig

Debug output

not applicable

Expected behavior

We are using consul-template to generate a config file that is bind mounted into a container. We expect that file to be updated in the container.

Actual behavior

What happens is the current implementation of the AtomicWrite method creates a temp file and copies it therefore not maintaining the inode, and therefore the bind mount points to the old inode and therefore the old content.

https://github.com/hashicorp/consul-template/blob/d1f1b0df1ce2ff246f1cdddf9090924d57c0303e/renderer/renderer.go#L122

Steps to reproduce

  1. bind mount a file in a container that is updated via consul-template
  2. change the contents of the file via a consul key being updated
  3. then check the file contents in the container and see it had not changed

References

phenixrizen avatar Aug 28 '20 21:08 phenixrizen

Hey @phenixrizen, thanks for taking the time to report this.

This is the a (the?) standard way of doing atomic file updates. File writes themselves are not atomic and if you don't want to end up with partially written files, writing them out fully then renaming it (an atomic operation) to the destination is the only way.

Can you bind mount the directory containing the file? That would work as it writes the temp file to the same directory.

eikenb avatar Aug 28 '20 21:08 eikenb