Skip to content

fix(DNR): prevent hanging on DNR APIs after optional permissions#411

Open
qixing-jk wants to merge 2 commits into
mainfrom
fix/359-auto-detect-hang-after-permission-grant
Open

fix(DNR): prevent hanging on DNR APIs after optional permissions#411
qixing-jk wants to merge 2 commits into
mainfrom
fix/359-auto-detect-hang-after-permission-grant

Conversation

@qixing-jk

@qixing-jk qixing-jk commented Jan 31, 2026

Copy link
Copy Markdown
Owner

#359

Summary by CodeRabbit

  • New Features

    • Added timeout protection and automatic retry logic for account session operations, preventing requests from hanging indefinitely.
    • Improved error handling to distinguish between transient failures and permission issues.
  • Tests

    • Added test coverage for timeout handling in cookie injection operations.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add timeout utility for Promises that may never settle
- Wrap DNR updateSessionRules with timeout and retry logic
- Ensure tests verify timeout behavior
- Move DNR constants to shared module
- Replace hardcoded values with imported constants
- Derive TIME_BUDGET_MS from TIMEOUT and MAX_ATTEMPTS
- Update AUTO_DETECT_SLOW_HINT_DELAY_MS to use TIME_BUDGET_MS
@dosubot

dosubot Bot commented Jan 31, 2026

Copy link
Copy Markdown

Related Documentation

Checked 4 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai

coderabbitai Bot commented Jan 31, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce timeout and retry mechanisms for DNR (Declarative Net Request) session rules operations. A new constants module defines timeout/retry parameters, utility functions provide promise timeout handling, the cookie injection logic integrates these timeouts with error classification, and tests verify the timeout behavior.

Changes

Cohort / File(s) Summary
DNR Constants
constants/dnr.ts
Defines timeout (5000ms), max attempts (2), and retry delay (250ms) constants for DNR session rule updates, with computed total time budget.
Timeout Utilities
utils/timeout.ts
Introduces TimeoutError class and helper functions: sleep() for delays and withTimeout() for promise timeout racing with configurable timeout duration and cleanup.
DNR Cookie Injection
utils/dnrCookieInjector.ts
Adds updateSessionRulesSafe() wrapper with timeout, retry, and error classification logic; integrates it into applyTempWindowCookieRule and removeTempWindowCookieRule for robust session rule handling.
DNR Cookie Injection Tests
tests/utils/dnrCookieInjector.test.ts
Adds test case verifying applyTempWindowCookieRule times out when updateSessionRules never settles; improves afterEach cleanup with real timer restoration.
Account Dialog Integration
features/AccountManagement/components/AccountDialog/hooks/useAccountDialog.ts
Updates AUTO_DETECT_SLOW_HINT_DELAY_MS to use imported DNR_UPDATE_SESSION_RULES_TIME_BUDGET_MS constant instead of hardcoded value.

Sequence Diagram

sequenceDiagram
    participant Client as applyTempWindowCookieRule
    participant Safe as updateSessionRulesSafe
    participant Timeout as withTimeout
    participant DNR as chrome.declarativeNetRequest
    
    Client->>Safe: Call with rules
    activate Safe
    Safe->>Timeout: Wrap updateSessionRules call with timeout
    activate Timeout
    Timeout->>DNR: updateSessionRules(rules)
    activate DNR
    alt Success
        DNR-->>Timeout: Resolves
        Timeout-->>Safe: Returns result
    else Timeout
        Note over Timeout: TimeoutError thrown
        Timeout-->>Safe: Rejects with timeout
        Safe->>Safe: Classify as timeout (retry)
    else Permission Error
        DNR-->>Timeout: Rejects with permission error
        Timeout-->>Safe: Rejects with permission error
        Safe->>Safe: Classify as permission (no retry)
    end
    deactivate DNR
    deactivate Timeout
    Safe-->>Client: Returns ruleId or null
    deactivate Safe
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #272: Extends and hardens the declarative-net-request cookie injector by adding timeout/retry mechanisms and constants to the same utils/dnrCookieInjector.ts module.

Poem

🐰 A timeout's here, no more delays,
Our cookies now won't hang for days,
With retries wise and time budgets clear,
The DNR requests won't disappear! 🍪⏱️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(DNR): prevent hanging on DNR APIs after optional permissions' directly and clearly describes the main change: adding timeout protection to DNR API calls to prevent hangs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/359-auto-detect-hang-after-permission-grant

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

Preview build ready for commit 94e3211.

Artifacts:

  • all-api-hub-3.10.0-chrome.zip
  • all-api-hub-3.10.0-firefox.zip
  • all-api-hub-3.10.0-sources.zip

Download from workflow run: https://github.com/qixing-jk/all-api-hub/actions/runs/21543851548

This build is for review only and is not released.

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.

1 participant