Skip to content

fix(web): prevent race conditions in concurrent wake lock requests - #152

Open
FaizanUllahDev wants to merge 8 commits into
fluttercommunity:mainfrom
FaizanUllahDev:fix/web-wake-lock-concurrency-150
Open

FaizanUllahDev wants to merge 8 commits into
fluttercommunity:mainfrom
FaizanUllahDev:fix/web-wake-lock-concurrency-150

Conversation

@FaizanUllahDev

@FaizanUllahDev FaizanUllahDev commented Oct 29, 2026 •

Copy link
Copy Markdown

Description

Fixes #150.

Problem

Concurrent enable() calls could trigger multiple wake-lock requests while sharing the same promise completer. When one request completed and cleared the shared reference, another callback could throw an unhandled TypeError.

The video fallback implementation had a similar concurrency issue.

Changes

  • Serialize concurrent wake-lock operations.
  • Prevent duplicate requests and inconsistent state transitions.
  • Handle rejected requests and allow retries.
  • Protect newer wake locks from stale release events.
  • Fix concurrency handling in the video fallback.
  • Preserve synchronous playback initiation for browser user activation.
  • Add 15 regression scenarios and automated CI checks.

Testing

  • Chromium 144: 15/15 mocked concurrency scenarios passed.
  • Chromium: HTMLVideoElement playback and pause verified.
  • Local Node.js regression scenarios passed.
  • Safari / iOS PWA device verification.
  • Flutter integration and upstream GitHub Actions checks.

Modified Files

  • wakelock_plus/lib/assets/no_sleep.js
  • wakelock_plus/test/no_sleep_concurrency.test.cjs
  • .github/workflows/checks.yml

Scope

Changes are limited to the web implementation, regression tests, and CI configuration. Native Android, iOS, macOS, Windows, and Linux implementations remain unchanged.

Comment thread wakelock_plus/lib/assets/no_sleep.js Resolved
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.

Web: TypeError: null is not an object (evaluating '_nativeEnabledCompleter.completeError') on overlapping enable() calls

2 participants