error handler of same domain can be called several times when it throws
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.3k
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 283
Description
- Version: Current tip of master (66f45e7e5b), but probably applies to all versions.
- Platform: All platforms.
- Subsystem: domain.
The following code:
'use strict';
const common = require('../common');
const domain = require('domain');
const http = require('http');
const server = http.createServer((req, res) => {
res.end();
});
let numDomainErrorListenerCalls = 0;
function performHttpRequestWithDomain(cb) {
const d = domain.create();
d.run(() => {
const req = http.get({
host: '127.0.0.1', port: server.address().port
}, (res) => {
res.on('data', () => {});
res.on('end', () => {
throw new Error('bang');
});
});
req.end();
});
d.on('error', (domainErr) => {
console.log(++numDomainErrorListenerCalls);
throw new Error('boom');
});
}
server.listen(0, '127.0.0.1', () => {
performHttpRequestWithDomain(common.mustCall(() => {
server.close();
}));
});
gives the following output:
$ ./node test/parallel/test-http-req-domain-stack.js
1
2
/Users/jgilli/dev/node/test/parallel/test-http-req-domain-stack.js:30
throw new Error('boom');
^
Error: boom
at Domain.d.on (/Users/jgilli/dev/node/test/parallel/test-http-req-domain-stack.js:30:11)
at Domain.emit (events.js:188:13)
at Domain.EventEmitter.emit (domain.js:430:20)
at Domain._errorHandler (domain.js:216:23)
at Domain._errorHandler (domain.js:244:33)
at Object.setUncaughtExceptionCaptureCallback (domain.js:132:29)
at process._fatalException (internal/process/execution.js:102:29)
The uncaught exception is expected. What is not expected as far as I understand is for the same domain's error handler to run more than once.
I believe the original intention of the domain's implementation is to pop the domains stack when a domain's error handler throw, so that the domain that handles that new error is the "parent" domain.
However, in the example above the same domain is pushed on the stack more than once. For instance, when an event is emitted from a nextTick callback, the same domain will be entered from the nextTick callbacks scheduler and then once again from the event emitter.
Pushing the same domain on the stack more than once makes sense so that the components that push a domain can pop it from the stack. However, I think we could probably replace the call to pop the stack once in the domain error handling code to remove all consecutive instances of that domain instead.
@nodejs/domains Thoughts?
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 test/parallel/test-http-req-domain-stack.js et reproduisez les appels répétés de l’error listener. Lisez lib/domain.js ainsi que internal/process/next_tick.js, en particulier les chemins de gestion de la pile référencés. C’est terminé lorsque la régression est couverte et que le gestionnaire d’erreurs du même domain n’est plus appelé à plusieurs reprises lorsqu’il lève une exception.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, nodejs
- Domaine
- backend, testing
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100