Unhandled rejection event in web streams when stream error is piped
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.4k
- Merge moyen
- 4 j 3 h
- PR mergées (30 j)
- 272
Description
Version
21.1.0
Platform
Linux kunigunde 6.5.9-arch2-1 #1 SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:52:20 +0000 x86_64 GNU/Linux
Subsystem
streams/web
What steps will reproduce the bug?
Run the following code:
import { ReadableStream } from "stream/web";
process.on('unhandledRejection', (err) => {
console.log(`Unhandled rejection: ${err.message}`);
});
const stream1 = new ReadableStream({
start(controller) {
controller.error(new Error('Test'));
},
});
const stream2 = new TransformStream();
stream1.pipeTo(stream2.writable);
try {
await stream2.readable.getReader().read();
} catch (err) {
console.log(`Caught error: ${err.message}`);
}
How often does it reproduce? Is there a required condition?
With the given code example, it happens every time.
It does not happen in the following situations:
- Reading from
stream1directly rather than piping it tostream2 - Reading from
stream2but notcatching the error but letting the app crash instead
What is the expected behavior? Why is that the expected behavior?
No unhandledRejection event should be triggered, since the exception is actually handled.
What do you see instead?
An unhandledRejection event is triggered. The output of the sample script is:
Caught error: Test
Unhandled rejection: Test
Workaround
I’m not sure if this has any unintended side effects, but catching the rejection by the promise returned by pipeTo() seems to solve the problem:
stream1.pipeTo(stream2.writable).catch(() => {});
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par exécuter la reproduction fournie et examinez le chemin streams/web pipeTo, en vous concentrant sur la façon dont son rejection est propagé lorsque le readable de destination est consommé. Le travail est terminé lorsque l’erreur du stream interceptée ne déclenche plus d’événement unhandledRejection, tandis que le comportement existant pour les erreurs interceptées reste intact.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Active
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 68/100