Web: TypeError: null is not an object (evaluating '_nativeEnabledCompleter.completeError') on overlapping enable() calls
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- dart, javascript
Direzione di ricerca
Parti da lib/assets/no_sleep.js, in enable() e nella gestione di _playVideoCompleter: ogni chiamata legge il _nativeEnabledCompleter a livello di modulo invece di un riferimento locale, quindi un completer già risolto e impostato a null fa crashare il successivo .then/.catch. Applica a entrambi i completers il pattern a riferimento locale suggerito dall'issue, poi verifica chiamando WakelockPlus.enable() ripetutamente senza attendere (Safari/web) ed esegui la suite di test del repo (dart test / flutter test) oltre a una build web per confermare che non rimane alcun rifiuto non gestito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Version: 1.7.0. The same code is still in main.
Platform: Web, Safari / iOS PWA
Description
In lib/assets/no_sleep.js, all calls to enable() share the module-level _nativeEnabledCompleter. Overlapping enable() calls can end up using the same completer while each sends its own navigator.wakeLock.request('screen'). The first request to settle completes the completer and sets it to null. When the next request settles, its handler calls _nativeEnabledCompleter.completeError(...) on null; on success it calls .complete() instead.
The TypeError is thrown inside a .catch handler of a promise that nothing awaits. Dart code can't catch it, so it surfaces as an unhandled rejection. Our Sentry has about 19K events of it, mostly from Safari, where wakeLock.request often rejects with NotAllowedError.
Steps to reproduce
Call WakelockPlus.enable() several times without awaiting, for example on every route change, in Safari.
Suggested fix
In each enable() call, keep a local reference to the completer and use that reference in .then / .catch, instead of reading the shared variable:
var completer = _nativeEnabledCompleter
navigator.wakeLock.request('screen')
.then(function (wakeLock) { /* ... / completer.complete(); if (_nativeEnabledCompleter === completer) _nativeEnabledCompleter = null })
.catch(function (err) { / ... */ completer.completeError(errorMessage); if (_nativeEnabledCompleter === completer) _nativeEnabledCompleter = null })
return completer.future
_playVideoCompleter is handled the same way and has the same problem.
Workaround
On our side, we now run enable() / disable() one at a time and skip a call when the wakelock is already in the requested state.
- Lingua principale
- Dart
- Stelle
- 110
- Fork
- 99
- Merge medio
- 9h 27m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fluttercommunity/wakelock_plus
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
fluttercommunity/wakelock_plus#117 · 2 commenti · 2 reazioni ·
-
window不能编译Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
-
wakelock_plus has malware?Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
Tutte le issue di fluttercommunity/wakelock_plus
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
fossasia/badgemagic-app#2016 ·
I maintainer di solito rispondono entro 1 giorno
-
bug P3 ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
QueryaHub/Querya-Desktop#1837 ·
I maintainer di solito rispondono entro 1 giorno
-
direct-code
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aaronified/fluenough#849 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
PATILYASHH/XPENC#179 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno