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

[PM-17658] Fix persist route to clear if service worker dies #13382

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

justindbaur
Copy link
Member

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-17658

📔 Objective

Fix delay to still trigger a cleanup even in the event that the service worker dies. By using a SchedulerLike based on our own TaskSchedulerService it will utilize a more long lived scheduling infrastructure when needed. When it's not needed it will still use setTimeout under the hood, just like the default scheduler in rxjs.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@justindbaur justindbaur requested a review from a team as a code owner February 12, 2025 22:04
@justindbaur justindbaur requested a review from coroiu February 12, 2025 22:04
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.

Project coverage is 35.31%. Comparing base (4cb8e85) to head (fb73db9).
Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
.../src/platform/scheduling/task-scheduler.service.ts 25.00% 6 Missing ⚠️
...rm/services/popup-view-cache-background.service.ts 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13382      +/-   ##
==========================================
+ Coverage   35.20%   35.31%   +0.10%     
==========================================
  Files        3126     3128       +2     
  Lines       92567    92610      +43     
  Branches    16857    16827      -30     
==========================================
+ Hits        32590    32705     +115     
+ Misses      57520    57445      -75     
- Partials     2457     2460       +3     

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

Copy link
Contributor

github-actions bot commented Feb 12, 2025

Logo
Checkmarx One – Scan Summary & Detailsf103f304-85c4-4b35-aed4-9a72e92b22e4

New Issues (4)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
HIGH CVE-2025-0995 Npm-electron-34.0.0 Vulnerable Package
HIGH CVE-2025-0996 Npm-electron-34.0.0 Vulnerable Package
HIGH CVE-2025-0997 Npm-electron-34.0.0 Vulnerable Package
HIGH CVE-2025-0998 Npm-electron-34.0.0 Vulnerable Package
Fixed Issues (3)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
LOW Client_JQuery_Deprecated_Symbols /apps/web/src/app/tools/reports/pages/weak-passwords-report.component.ts: 94
LOW Client_JQuery_Deprecated_Symbols /apps/web/src/app/tools/reports/pages/weak-passwords-report.component.ts: 87
LOW Client_JQuery_Deprecated_Symbols /apps/browser/src/autofill/background/overlay.background.ts: 756

return new TaskSchedulerSheduler(taskScheduler, taskName);
}

class TaskSchedulerSheduler implements SchedulerLike {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo?: SchedulerScheduler ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha no... but I am definitely open to other names. It's an implementation of Scheduler based on our service named TaskSchedulerService (but I kind of wish we had dropped the Service on it. So I prefixed the thing it is with its modifier. The type name is an implementation detail and not exposed anywhere if that changes any of your feelings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, it's a Scheduler that belong to the TaskScheduler, I don't have any better suggestion, except maybe just Scheduler 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I kind of like TaskSchedulerScheduler more at least as a thing that doesn't have to be consumed by other directly.

* @param taskName The name of the task that the handler should be registered and scheduled based on.
* @returns A SchedulerLike object that can be passed in to RXJS operators like `delay` and `timeout`.
*/
export function toScheduler(
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: could you add an @example here with some documentation about the expected behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an example a little bit more of an explanation on our side and a couple links to helpful guides on https://rxjs.dev, anything else you think would be nice?

Comment on lines -90 to +103
switchMap(([port]) => fromChromeEvent(port.onDisconnect).pipe(delay(1000 * 60 * 2))),
switchMap(([port]) =>
fromChromeEvent(port.onDisconnect).pipe(
delay(
1000 * 60 * 2,
toScheduler(this.taskSchedulerService, ScheduledTaskNames.clearPopupViewCache),
),
),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Do you know why we are delaying these emissions inside of a nested pipe? Are we implementing our own debounce? Could this be rewritten like this: ?

switchMap(([port]) => fromChromeEvent(port.onDisconnect)),
debounceTime(
  1000 * 60 * 2, 
  toScheduler(this.taskSchedulerService, ScheduledTaskNames.clearPopupViewCache)
),

or am I missing some subtlety?

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it shouldn't need to be nested but it's not to try and achieve a debounce. Although a debounce would probably work fine also. This is just trying to clear the view cache 2 minutes after a popup closes, an event that can't happen that much (without opening a new one which should cancel the delay), so it's not needed either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh ok we're not debouncing, we just want to wait 2 minutes UNLESS a new window appears in which case we want to cancel the timeout. Looks good in that case, clever but not immediately obvious :)

@justindbaur justindbaur requested a review from coroiu February 13, 2025 17:46
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