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

Disable lock file if directory does not exist or no permissions #2190

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

Ruadhri17
Copy link
Contributor

Proposed changes

This PR disable lock file mechanism when {run.path}/lock does not exist or directory is not writable.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#2131

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@Ruadhri17 Ruadhri17 temporarily deployed to Test Pull Request August 24, 2023 16:59 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #2190 (fdcb98c) into main (3e37b35) will decrease coverage by 0.2%.
Report is 15 commits behind head on main.
The diff coverage is 0.0%.

❗ Current head fdcb98c differs from pull request most recent head 3987f99. Consider uploading reports for the commit 3987f99 to get more accurate results

Additional details and impacted files
Files Changed Coverage Δ
crates/common/flockfile/src/unix.rs 66.4% <0.0%> (+0.9%) ⬆️
crates/core/tedge_agent/src/agent.rs 0.0% <0.0%> (ø)
crates/core/tedge_mapper/src/main.rs 0.0% <0.0%> (ø)

... and 16 files with indirect coverage changes

@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
257 0 5 257 100 45m28.236s

Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

The proposed check is not working: if a user cannot write the lock while another user could, then this user will not be able to run the agent or the mapper.

A better approach is to leverage the error returned by Flockfile::new_lock(), ignoring the error if !error.non_exclusive_access()

crates/common/flockfile/src/unix.rs Outdated Show resolved Hide resolved
@didier-wenzek
Copy link
Contributor

A better approach is to leverage the error returned by Flockfile::new_lock(), ignoring the error if !error.non_exclusive_access()

The fix is a bit more involved as non_exclusive_access() should check errno has been set to EAGAIN or EACCES.

@Ruadhri17 Ruadhri17 temporarily deployed to Test Pull Request August 25, 2023 18:11 — with GitHub Actions Inactive
Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

The code is correct and behaves as described by #2131

However, the warning message published when locks are disabled could be more useful for the user who intends to enable locks.

$ tedge config set run.path /tmp
$ target/debug/tedge-mapper --debug collectd 
2023-08-28T07:34:59.955514889Z  INFO flockfile::unix: The locking mechanism is not active, so it does not prevent running multiple instances of tedge-mapper-collectd.

This should tell the user why locking mechanism is not active.

The locking mechanism is not active, as `/tmp/lock` is not a directory with write access.

Might be a bit verbose though. @reubenmiller what's your point of view?

@reubenmiller
Copy link
Contributor

The locking mechanism is not active, as `/tmp/lock` is not a directory with write access.

I really like the Didier's suggestion, so please use the statement.

The locking mechanism is not active, as `/tmp/lock` is not a directory with write access.

Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
@Ruadhri17 Ruadhri17 temporarily deployed to Test Pull Request August 28, 2023 15:40 — with GitHub Actions Inactive
Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants