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

Handle library scan failure gracefully #3410

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

mikiher
Copy link
Contributor

@mikiher mikiher commented Sep 12, 2024

This is in partial response to #3406

Library scan is a complex process and can fail in unexpected ways.
This tries wrap it up with a try-catch block, do the sensible things on error, save the scan log, and not crash the server.

There are a couple of questions I still have regarding the code:

  • In the following code:
        if (canceled && !libraryScan.totalResults) {
          task.setFinished('Scan canceled')
          TaskManager.taskFinished(task)
    
          const emitData = libraryScan.getScanEmitData
          emitData.results = null
          return
        }
    what is the last part trying to achieve? it seems it has no effect. Also, the premature return prevents some cleanups from happening.
  • In the following code:
      if (libraryScan.totalResults) {
        libraryScan.saveLog()
      }
    Why do we check library.Scan.totalResults? don't we want to save the scan log anyway?

@mikiher mikiher marked this pull request as ready for review September 12, 2024 16:20
@advplyr
Copy link
Owner

advplyr commented Sep 12, 2024

Way back when scans showed a persistent toast and when the scan emit data results were null that was when it would show "canceled" in the toast. It looks like that last part was accidently leftover when I refactored. It doesn't do anything.

If the user were to start a scan and cancel it quickly I don't think we want to update the lastScan, lastScanVersion and lastScanMetadataPrecedence. I don't think it would matter much if we did though.

I'm not sure why I setup the scan log to only save when it has updates. I think we can save it regardless and we can also save it if the scan was canceled.

@mikiher
Copy link
Contributor Author

mikiher commented Sep 12, 2024 via email

@mikiher
Copy link
Contributor Author

mikiher commented Sep 13, 2024

If the user were to start a scan and cancel it quickly I don't think we want to update the lastScan, lastScanVersion and lastScanMetadataPrecedence. I don't think it would matter much if we did though.

Updating lastScan and lastScanVersion probably won't matter much, but if we update lastScanMetadataPrecedence and this scan had forceRescan=true (which happens when metadata precedence changes), then the next scan will have forceRescan=false (assuming data precedence hasn't changed again) - is that the intended behavior? I'm not sure. What do you think?

It seems to me that for the sake of simplicity, we should only update all those fields after a complete full scan was run - that's what I implemented.

This is ready for review now.

@advplyr
Copy link
Owner

advplyr commented Sep 13, 2024

Yeah you're right. We don't want to update lastScanMetadataPrecedence on a cancel because when the metadata precedence changes we want the next scan to do a full re-scan.

Thanks!

@advplyr advplyr merged commit 854f308 into advplyr:master Sep 13, 2024
5 checks passed
@mikiher mikiher deleted the library-scan-try-catch branch November 18, 2024 09:42
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.

2 participants