Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iroh): do not remove the rpc lockfile if an iroh node is already running #2013

Merged
merged 5 commits into from
Feb 9, 2024

Conversation

ramfox
Copy link
Contributor

@ramfox ramfox commented Feb 8, 2024

Description

Previously, we were running RpcStatus::clear, every time we ran the iroh start command (start::run_with_command).

This meant that even when we correctly exited the iroh start command in with the error "iroh is already running", we would then remove the rpc lock file, even though iroh was still running in a different process.

Any subsequent calls to iroh console or any other iroh commands that expected an iroh node to be running, would assume that a node was no longer running because the rpc lock file was gone.

This PR adds a new concrete AlreadyRunningError that we return from start_node. Before we run RpcStatus::clear, we check for the AlreadyRunningError, and do not clear the lockfile if that error is present.

closes #2002

Notes & open questions

One big change in this PR

Using the iroh_data_root function makes it impossible to test anything at the iroh::start level, because the IROH_DATA_DIR env var makes sure that nothing can be tested in isolation. Setting the env var in one test, clobbers setting it in another.

I have a commit that adjusts the code to:

  • run iroh_data_dir() once in main.rs
  • cascades the iroh_data_dir down through the code from there
  • remove any other references to calling iroh_data_dir anywhere else

This mostly effects commands::console and commands::start

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

@ramfox ramfox requested a review from dignifiedquire February 8, 2024 22:39
@ramfox ramfox self-assigned this Feb 8, 2024
@ramfox ramfox added the fix Fixes a bug label Feb 8, 2024
@ramfox ramfox added this to the v0.13.0 milestone Feb 8, 2024
@ramfox ramfox marked this pull request as ready for review February 9, 2024 02:21
@ramfox ramfox requested a review from dignifiedquire February 9, 2024 02:31
@flub
Copy link
Contributor

flub commented Feb 9, 2024

I have a commit that adjusts the code to:

* run `iroh_data_dir()` once in `main.rs`

* cascades the `iroh_data_dir` down through the code from there

* remove any other references to calling `iroh_data_dir` anywhere else

Would love some more eyes and opinions tho.

excellent choice

Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much much better than what we currently have!

@ramfox ramfox added this pull request to the merge queue Feb 9, 2024
Merged via the queue into main with commit a5c0db3 Feb 9, 2024
18 checks passed
@ramfox ramfox deleted the double_start_bug branch February 9, 2024 17:29
github-merge-queue bot pushed a commit that referenced this pull request Feb 17, 2024
## 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.
fubuloubu pushed a commit to ApeWorX/iroh that referenced this pull request Feb 21, 2024
…running (n0-computer#2013)

## Description

Previously, we were running `RpcStatus::clear`, every time we ran the
`iroh start` command (`start::run_with_command`).

This meant that even when we correctly exited the `iroh start` command
in with the error "iroh is already running", we would then remove the
rpc lock file, even though iroh was still running in a different
process.

Any subsequent calls to `iroh console` or any other iroh commands that
expected an iroh node to be running, would assume that a node was *no
longer running* because the rpc lock file was gone.

This PR adds a new concrete `AlreadyRunningError` that we return from
`start_node`. Before we run `RpcStatus::clear`, we check for the
`AlreadyRunningError`, and do not clear the lockfile if that error is
present.

closes n0-computer#2002 

## Notes & open questions

**One big change in this PR**

Using the `iroh_data_root` function makes it impossible to test anything
at the `iroh::start` level, because the `IROH_DATA_DIR` env var makes
sure that nothing can be tested in isolation. Setting the `env var` in
one test, clobbers setting it in another.

I have a commit that adjusts the code to:
- run `iroh_data_dir()` once in `main.rs`
- cascades the `iroh_data_dir` down through the code from there
- remove any other references to calling `iroh_data_dir` anywhere else

This mostly effects `commands::console` and `commands::start`

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [x] Tests if relevant.
fubuloubu pushed a commit to ApeWorX/iroh that referenced this pull request Feb 21, 2024
…2032)

## Description

Fixes n0-computer#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 n0-computer#2013 and I think `author new
--switch` is the only command affected

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fixes a bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

If you do iroh start twice, you can't use iroh console anymore
3 participants