serialise the agent-sockets and gateway publishes and give each its own tmp file
Closes #6094
This commit is contained in:
parent
970ee83a93
commit
febac5eaa9
1 changed files with 128 additions and 39 deletions
|
|
@ -193,26 +193,30 @@ pub async fn write(names: &[String]) -> Result<()> {
|
|||
std::fs::create_dir_all(parent)
|
||||
.with_context(|| format!("create dir {}", parent.display()))?;
|
||||
}
|
||||
let tmp = path.with_extension("conf.tmp");
|
||||
std::fs::write(&tmp, &body).with_context(|| format!("write tmp {}", tmp.display()))?;
|
||||
// Mode set on the TMP file, before the rename, because a rename
|
||||
// carries the source's mode and owner and discards the destination's.
|
||||
// The tmpfiles rule declaring 0644 is `f` (create-if-absent), so it
|
||||
// never re-applies: from the first republish on, the published mode is
|
||||
// whatever this process's umask happened to produce. That is fine
|
||||
// today and becomes a dead gateway the day anything tightens c0re's
|
||||
// umask, since nginx reads this file as a different, unprivileged
|
||||
// user. Making it explicit means the mode is a property of the
|
||||
// publisher rather than of an unrelated unit's settings.
|
||||
std::fs::set_permissions(&tmp, std::fs::Permissions::from_mode(0o644))
|
||||
.with_context(|| format!("chmod tmp {}", tmp.display()))?;
|
||||
std::fs::rename(&tmp, &path).with_context(|| {
|
||||
format!(
|
||||
"rename {} -> {} (atomic publish)",
|
||||
tmp.display(),
|
||||
path.display()
|
||||
)
|
||||
})?;
|
||||
let tmp = agent_sockets::unique_tmp(&path);
|
||||
let published = (|| -> Result<()> {
|
||||
std::fs::write(&tmp, &body).with_context(|| format!("write tmp {}", tmp.display()))?;
|
||||
// Mode set on the TMP file, before the rename, because a rename
|
||||
// carries the source's mode and owner and discards the destination's.
|
||||
// The tmpfiles rule declaring 0644 is `f` (create-if-absent), so it
|
||||
// never re-applies: from the first republish on, the published mode is
|
||||
// whatever this process's umask happened to produce. That is fine
|
||||
// today and becomes a dead gateway the day anything tightens c0re's
|
||||
// umask, since nginx reads this file as a different, unprivileged
|
||||
// user. Making it explicit means the mode is a property of the
|
||||
// publisher rather than of an unrelated unit's settings.
|
||||
std::fs::set_permissions(&tmp, std::fs::Permissions::from_mode(0o644))
|
||||
.with_context(|| format!("chmod tmp {}", tmp.display()))?;
|
||||
std::fs::rename(&tmp, &path).with_context(|| {
|
||||
format!(
|
||||
"rename {} -> {} (atomic publish)",
|
||||
tmp.display(),
|
||||
path.display()
|
||||
)
|
||||
})?;
|
||||
Ok(())
|
||||
})();
|
||||
agent_sockets::remove_tmp_on_err(&tmp, published)?;
|
||||
// Reset backoff so a fresh topology change gets an immediate attempt,
|
||||
// not a stale cooldown from a previous failure.
|
||||
LAST_FAILED_RELOAD.store(0, Ordering::Relaxed);
|
||||
|
|
|
|||
Loading…
Reference in a new issue