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 error modal not showing when in non-secure context #4499

Merged
merged 6 commits into from
Mar 3, 2025

Conversation

MikesGlitch
Copy link
Contributor

@MikesGlitch MikesGlitch commented Mar 1, 2025

The SharedArrayBuffer error screen wasn't always showing for users not using HTTPS - it was the cause of some github issues. The cause was (another) race condition. The problem & fix is very similar to this: #4375

The Fatal error message was the first message we were attempting to send the worker. If the client wasn't ready to receive the message it would just hang on the loading screen. The solution is to add retries.

image

To replicate:

  • run the app on localhost
  • use your ipv4 address to load actual

The old code would hang on the loading screen, the new code will show the Fatal error.

NOTE: I noticed the old code would sometimes work and sometimes not. I found it easier to replicate when devtools was closed.

Copy link

netlify bot commented Mar 1, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit cdd6392
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67c39360f00f1e0008f046d0
😎 Deploy Preview https://deploy-preview-4499.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Mar 1, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
18 7.06 MB → 7.06 MB (+84 B) +0.00%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/platform/client/fetch/index.browser.ts 📈 +91 B (+2.56%) 3.47 kB → 3.56 kB
src/components/App.tsx 📉 -7 B (-0.11%) 6.16 kB → 6.15 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 4.36 MB → 4.36 MB (+84 B) +0.00%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/de.js 112 kB 0%
static/js/es.js 58.26 kB 0%
static/js/en-GB.js 96.59 kB 0%
static/js/fr.js 89.9 kB 0%
static/js/nl.js 95.56 kB 0%
static/js/en.js 103.63 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/uk.js 111.11 kB 0%
static/js/AppliedFilters.js 10.8 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/narrow.js 86.26 kB 0%
static/js/pt-BR.js 110.57 kB 0%
static/js/wide.js 102.9 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Mar 1, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.34 MB → 1.34 MB (-3 B) -0.00%
Changeset
File Δ Size
packages/loot-core/src/platform/server/connection/index.web.ts 📉 -3 B (-0.07%) 4.29 kB → 4.29 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
kcab.worker.js 1.34 MB → 1.34 MB (-3 B) -0.00%

Unchanged

No assets were unchanged

@MikesGlitch MikesGlitch marked this pull request as ready for review March 1, 2025 23:04
@MikesGlitch MikesGlitch changed the title Init when not ssl 🐛 Fix error modal not showing when in non-secure context Mar 1, 2025
Copy link
Contributor

coderabbitai bot commented Mar 1, 2025

Walkthrough

The pull request introduces changes to enhance error handling during application initialization across several files. In the browser-server.js file, a retry mechanism for posting messages is implemented, utilizing a constant RECONNECT_INTERVAL_MS of 200 milliseconds and a maximum of 500 attempts defined by MAX_RECONNECT_ATTEMPTS. A new function, postMessageWithRetry, is added to manage the message sending process, which is triggered upon initialization failures. The App.tsx file modifies the dependency array in a useEffect hook to exclude certain variables, reducing the risk of crashes in the Electron environment. Additionally, the index.browser.ts file now sends an acknowledgment message to the global worker during initialization failures, while a minor textual correction is made in the logging message within index.web.ts.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • youngcw
  • MikesGlitch
✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/desktop-client/src/browser-server.js (1)

62-62: Log message could be more descriptive

The log message has been simplified from what was likely more descriptive before.

-console.info('init');
+console.info('Initializing backend...');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8900627 and 55eff84.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4499.md is excluded by !**/*.md
📒 Files selected for processing (4)
  • packages/desktop-client/src/browser-server.js (3 hunks)
  • packages/desktop-client/src/components/App.tsx (1 hunks)
  • packages/loot-core/src/platform/client/fetch/index.browser.ts (1 hunks)
  • packages/loot-core/src/platform/server/connection/index.web.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/loot-core/src/platform/server/connection/index.web.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (7)
packages/desktop-client/src/components/App.tsx (1)

130-132: Dependency list reduction looks good

Removing cloudFileId and t from the dependencies array is a valid approach to prevent the initialization logic from re-running when these values change, which aligns with the comment about preventing Electron crashes.

packages/loot-core/src/platform/client/fetch/index.browser.ts (1)

110-112: Good addition of acknowledgment message

Adding this acknowledgment message when an app-init-failure occurs provides a clear way for the client to signal that it has received the failure message, which pairs well with the retry mechanism in browser-server.js.

packages/desktop-client/src/browser-server.js (5)

39-56: Well-structured retry mechanism

The implementation of constants and a dedicated retry function is a clean approach to solving the race condition mentioned in the PR objectives. The retry interval and maximum attempts are reasonably configured.


72-76: Good application of retry mechanism

Using the retry function here ensures the SharedArrayBuffer error message will be consistently delivered to the client even if it's not immediately ready to receive it.


87-90: Consistent error handling approach

The same retry mechanism is correctly applied to this error case as well, maintaining consistency in the error handling approach.


97-100: Clean interval cleanup

Adding logic to clear the retry interval when an acknowledgment is received prevents unnecessary continued retry attempts and potential resource waste.


103-106: Complete error handling coverage

The retry mechanism is appropriately applied to the catch block as well, ensuring all potential initialization failures are handled consistently.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/desktop-client/src/browser-server.js (1)

39-106: Consider resetting reconnectAttempts when starting a new retry sequence.

While the implementation works as is, the reconnectAttempts counter isn't reset between different failure scenarios. This could lead to reduced retry attempts if multiple failures occur in sequence.

 const postMessageWithRetry = message => {
+  reconnectAttempts = 0;
   const reconnectToClientInterval = setInterval(() => {
     self.postMessage(message);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55eff84 and cdd6392.

📒 Files selected for processing (1)
  • packages/desktop-client/src/browser-server.js (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Visual regression
  • GitHub Check: Functional
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (7)
packages/desktop-client/src/browser-server.js (7)

39-41: Constants seem reasonable for retry mechanism.

The constants provide a good balance between reliability and performance: 200ms interval with up to 500 attempts gives a maximum retry window of 100 seconds, which should be sufficient for most network conditions and client initialization times.


43-54: Well-implemented retry mechanism with proper termination.

The postMessageWithRetry function implements a time-based retry mechanism that will continue attempting to deliver the message to the client until acknowledged. This effectively addresses the race condition mentioned in the PR objectives where the client might not be ready to receive the first message.


56-56: Good approach using a module-scoped variable for interval management.

Using a module-scoped variable appInitFailureInterval allows for proper cleanup across different code paths.


71-75: Retry mechanism for SharedArrayBuffer error is appropriate.

This change addresses the core issue from the PR objectives where the SharedArrayBuffer error screen wasn't consistently displayed for non-HTTPS users.

We need to retry the messages here because can't be sure the client is ready when we send the message. This is only true for this init code because it's the first interaction with the worker. If we get passed this point in the app we know we have the connection.


86-90: Properly handling IDBFailure with retry mechanism.

The retry implementation for IDBFailure ensures consistent error message delivery, improving user experience when IndexedDB initialization fails.


96-99: Effective cleanup mechanism for acknowledged failures.

This is a critical part of the implementation that stops the retries once the client has acknowledged receipt of the failure message, preventing unnecessary message processing.


102-106: Comprehensive error handling with retry for backend initialization failures.

This change ensures that backend initialization errors are consistently communicated to the client, completing the robust error handling system.

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Nice! I've seen this cause a few reports in Discord.

@MikesGlitch MikesGlitch merged commit 17c4d16 into actualbudget:master Mar 3, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants