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: inotify read timeout not in ms #5876

Merged
merged 3 commits into from Feb 26, 2024

Conversation

grembo
Copy link
Contributor

@grembo grembo commented Feb 23, 2024

This was off by a factor of 1000, leading to a lot more invocations of the loop body than necessary.

Proposed change

Calculate the timeout passed to inotify.read to be in milliseconds (as required by the function) instead of seconds.

The issue becomes easily perceivable when setting PAPERLESS_CONSUMER_INOTIFY_DELAY to a high number, so that the while loop becomes obvious in tools like top.

Type of change

  • Bug fix: non-breaking change which fixes an issue.
  • New feature / Enhancement: non-breaking change which adds functionality. Please read the important note above.
  • Breaking change: fix or feature that would cause existing functionality to not work as expected.
  • Documentation only.
  • Other. Please explain:

Checklist:

  • I have read & agree with the contributing guidelines.
  • If applicable, I have included testing coverage for new code in this PR, for backend and / or front-end changes.
  • If applicable, I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.
  • If applicable, I have checked that all tests pass, see documentation.
  • I have run all pre-commit hooks, see documentation.
  • I have made corresponding changes to the documentation as needed.
  • I have checked my modifications for any breaking changes.

This was off by a factor of 1000, leading to a lot more invocations
of the loop body than necessary.
@paperless-ngx-secretary
Copy link

Hello @grembo,

thank you very much for submitting this PR to us!

This is what will happen next:

  1. My robotic colleagues will check your changes to see if they break anything. You can see the progress below.
  2. Once that is finished, human contributors from paperless-ngx review your changes. Since this seems to be a small change, only a single contributor has to review your changes.
  3. Please improve anything that comes up during the review until your pull request gets approved.
  4. Your pull request will be merged into the dev branch. Changes there will be tested further.
  5. Eventually, changes from you and other contributors will be merged into main and a new release will be made.

Please allow up to 7 days for an initial review. We're all very excited about new pull requests but we only do this as a hobby.
If any action will be required by you, please reply within a month.

@github-actions github-actions bot added the bug Bug report or a Bug-fix label Feb 23, 2024
Copy link

codecov bot commented Feb 23, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 96.90%. Comparing base (7f8f7fb) to head (d2cf1b8).

❗ Current head d2cf1b8 differs from pull request most recent head 184204e. Consider uploading reports for the commit 184204e to get more accurate results

Files Patch % Lines
...documents/management/commands/document_consumer.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #5876   +/-   ##
=======================================
  Coverage   96.90%   96.90%           
=======================================
  Files         405      405           
  Lines       16178    16179    +1     
  Branches     1170     1170           
=======================================
+ Hits        15678    15679    +1     
  Misses        500      500           
Flag Coverage Δ
backend 95.59% <88.88%> (+<0.01%) ⬆️
frontend 98.48% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shamoon
Copy link
Member

shamoon commented Feb 24, 2024

Seems like a good catch to me, thanks. I'll let the person generally most versed in this side of things chime in before merging.

https://github.com/chrisjbillington/inotify_simple/blob/76e8af8705ee4fb3acd926d66a1ba3de0f5d78d5/inotify_simple.py#L124

@shamoon shamoon added this to the Next Bugfix Release milestone Feb 24, 2024
@shamoon shamoon changed the title Fix inotify read timeout Fix: inotify read timeout not in ms Feb 24, 2024
@paperless-ngx paperless-ngx deleted a comment from sonarcloud bot Feb 24, 2024
Copy link
Member

@stumpylog stumpylog left a comment

Choose a reason for hiding this comment

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

Good catch, but lets tweak it a little bit

Lets calculate inotify_debounce * 1000 only once, and toss a _ms so no one forgets this value is in milliseconds

@grembo
Copy link
Contributor Author

grembo commented Feb 25, 2024

@stumpylog Do you mean something like this? Note that we still need a seconds representation of inotify_debounce within the loop body - therefore my solution would have been to rename it to inotify_debounce_secs (like I did), but keep the multiplication * 1000 - this iteration introduces the extra variable like requested (and also renames timeout to timeout_ms to make this explicit), like this:

timeout_ms = inotify_debounce_secs * 1000

There are certainly many different ways to resolve this ^_^

@paperless-ngx paperless-ngx deleted a comment from grembo Feb 25, 2024
Copy link
Member

@stumpylog stumpylog left a comment

Choose a reason for hiding this comment

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

Looks good, thank you

@stumpylog stumpylog enabled auto-merge (squash) February 26, 2024 00:40
@stumpylog stumpylog merged commit 7606417 into paperless-ngx:dev Feb 26, 2024
15 checks passed
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion or issue for related concerns. See our contributing guidelines for more details.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backend bug Bug report or a Bug-fix small-change
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants