Skip to content

Commit fea92ac

Browse files
fix(console): prevent deadlock in author new --switch (#2032)
## Description Fixes #2024 This was caused by a read attempt over a lock nested inside a write lock. Thw write lock being `let mut inner = self.0.write()` and the read lock in `self.iroh_data_dir()` ## Notes & open questions I checked the rest of the code in #2013 and I think `author new --switch` is the only command affected ## Change checklist - [ ] Self-review. - [ ] Documentation updates if relevant. - [ ] Tests if relevant.
1 parent e7af74d commit fea92ac

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

iroh/src/config.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,13 @@ impl ConsoleEnv {
268268
/// Will error if not running in the Iroh console.
269269
/// Will persist to a file in the Iroh data dir otherwise.
270270
pub fn set_author(&self, author: AuthorId) -> anyhow::Result<()> {
271+
let author_path = ConsolePaths::DefaultAuthor.with_root(self.iroh_data_dir());
271272
let mut inner = self.0.write();
272273
if !inner.is_console {
273274
bail!("Switching the author is only supported within the Iroh console, not on the command line");
274275
}
275276
inner.author = Some(author);
276-
std::fs::write(
277-
ConsolePaths::DefaultAuthor.with_root(self.iroh_data_dir()),
278-
author.to_string().as_bytes(),
279-
)?;
277+
std::fs::write(author_path, author.to_string().as_bytes())?;
280278
Ok(())
281279
}
282280

0 commit comments

Comments
 (0)