GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Domains inhibit uncaughtException error handling · Issue #3607 · nodejs/node

Domains inhibit uncaughtException error handling #3607

New issue
Copy link
New issue
Copy link
Closed
Closed
Domains inhibit uncaughtException error handling#3607
Copy link
Labels
confirmed-bugIssues and PRs for confirmed bugs.domainIssues and PRs related to the domain subsystem.

Description

@piscisaureus
piscisaureus
opened on Oct 30, 2015
Issue body actions

In the test case below, I would expect the uncaughtException handler to run (since the domain doesn't have an error event handler), but it doesn't.

Verified with node v0.10.39 and v4.2.1.

var domain = require('domain');

var d = domain.create();
d.enter();

process.on('uncaughtException', function(e) {
  console.log('Uncaught exception: ', e);
});

setTimeout(function() {
  throw new Error('Bla!');
}, 1);

Activity

Next
  1. piscisaureus
    added
    domainIssues and PRs related to the domain subsystem.
    on Oct 30, 2015
  2. evanlucas commented on Oct 30, 2015

    @evanlucas
    evanlucas
    on Oct 30, 2015
    Contributor
    More actions

    It is actually caught with v0.12

  3. evanlucas commented on Oct 30, 2015

    @evanlucas
    evanlucas
    on Oct 30, 2015
    Contributor
    More actions

    This worked for me in v4.0.0 as well. Looks like https://github.com/nodejs/node/pull/3036/files re-introduced the regression. /cc @misterdjules

  4. misterdjules commented on Oct 30, 2015

    @misterdjules
    misterdjules
    on Oct 30, 2015
    More actions

    @evanlucas The 'uncaughtException' event is emitted with v0.12.7, but not with a build of the tip of node's v0.12 branch.

    It seems that the problem has been there for a long time on v0.10, and is fixed by the following patch:

    diff --git a/src/node.js b/src/node.js
    index ab56040..5aec260 100644
    --- a/src/node.js
    +++ b/src/node.js
    @@ -229,7 +229,7 @@
         // and exit if there are no listeners.
         process._fatalException = function(er) {
           var caught = false;
    -      if (process.domain) {
    +      if (process.domain && process.domain.listeners('error').length > 0) {
             var domain = process.domain;
             var domainModule = NativeModule.require('domain');
             var domainStack = domainModule._stack;
    

    On v0.12 and v4.x, this is a regression that was introduced by me with nodejs/node-v0.x-archive#25835 and #3036 respectively.

    Here's a patch for v0.12 and v4.x that fixes the issue:

    diff --git a/lib/domain.js b/lib/domain.js
    index 87a4707..b5fc392 100644
    --- a/lib/domain.js
    +++ b/lib/domain.js
    @@ -80,7 +80,13 @@ Domain.prototype._errorHandler = function errorHandler(er) {
       var self = this;
    
       function emitError() {
    -    var handled = self.emit('error', er);
    +    var handled = false;
    +
    +    if (self.listeners('error').length === 0) {
    +      return false;
    +    }
    +
    +    handled = self.emit('error', er);
    
         // Exit all domains on the stack.  Uncaught exceptions end the
         // current tick and no domains should be left on the stack
    

    These patches were put together very quickly, and somehow feel a bit hacky. I haven't had the time to investigate their impact on other use cases.

    Also, while the issue with v0.10 hasn't been introduced by my change to support --abort-on-uncaught-exception when domains are used, the same changes are responsible for this regression on v0.12 and v4.x.

    So it's probably worth it to take a bit more time to see if these changes could be implemented in a different way that would not introduce this regression.

    I'll try to find more time this week-end to come up with the best fixes possible and I'll write something up here.

    Thanks for reporting the issue!

  5. evanlucas commented on Oct 30, 2015

    @evanlucas
    evanlucas
    on Oct 30, 2015
    Contributor
    More actions

    Thanks for the in-depth explanation @misterdjules. From playing around with it, it looks like process._fatalException currently is being called twice. Not sure if that helps or not, but couldn't really make any other headway right now.

  6. misterdjules
    added
    v0.10
    v0.12
    v4.x
    master
    v5.x
    on Oct 30, 2015
  7. misterdjules commented on Oct 30, 2015

    @misterdjules
    misterdjules
    on Oct 30, 2015
    More actions

    @nodejs/tsc @nodejs/collaborators I've added the following labels: v0.10, v0.12, v4.x, v5.x and master to identify issues that affect these versions. I find it's handy to determine what versions are affected by a given problem without having to read through the whole thread again.

    In this case, all these labels where set on this issue because after careful examination, it affects all these versions.

  8. misterdjules commented on Oct 30, 2015

    @misterdjules
    misterdjules
    on Oct 30, 2015
    More actions

    From playing around with it, it looks like process._fatalException currently is being called twice

    @evanlucas Indeed, the reason is that we enter a domain twice: once with the explicit call to d.enter() and a second time when calling the timer's callback.

    Then, when handling the error thrown in the domain at the top of the stack, we call EventEmitter.prototype.emit('error') on an instance that doesn't have an 'error' event handler. So it throws an error, thus calling process._fatalException again.

    For v0.10 though the problem is slightly different: we we either have domains on the stack and handle errors through these domains, or emit 'uncaughtException'.

    Anyway, we need to think a bit more about this to come up with a fix that hopefully won't cause more regressions, and the first step is probably to add more tests, beginning with the code in the description of this issue.

  9. priyavivek1 commented on Oct 30, 2015

    @priyavivek1
    priyavivek1
    on Oct 30, 2015
    More actions

    All, Do we have any ETA for this as we are heading towards production soon..

  10. misterdjules commented on Oct 30, 2015

    @misterdjules
    misterdjules
    on Oct 30, 2015
    More actions

    @priyavivek1 I should be able to come up with a good candidate for a fix early next week. Then it'll have to go through the usual review/update cycle, and then it'll have to make it into a release. In other words, it's a bit early to give an ETA, but I'll update this issue early next week with next steps, unless someone else takes care of it before me.

  11. priyavivek1 commented on Nov 2, 2015

    @priyavivek1
    priyavivek1
    on Nov 2, 2015
    More actions

    @misterdjules : We are on node version 0.10.39 and would be requiring a fix on that top of that. Thanks

  12. 39 remaining items

  13. misterdjules
    closed this as completedin 425a354on Dec 11, 2015
  14. misterdjules
    added 5 commits that reference this issue on Dec 11, 2015

    domains: fix handling of uncaught exceptions

    This issue will close once commit 20a6656 is merged into the 'master' branch.
    20a6656

    domains: fix handling of uncaught exceptions

    This issue will close once commit e8a6b65 is merged into the 'main' branch.
    e8a6b65

    domains: fix handling of uncaught exceptions

    This issue will close once commit 16417cc is merged into the 'main' branch.
    16417cc

    domains: fix handling of uncaught exceptions

    This issue will close once commit 25cded4 is merged into the 'main' branch.
    25cded4

    domains: fix handling of uncaught exceptions

    This issue will close once commit 9cae9b2 is merged into the 'main' branch.
    9cae9b2
  15. misterdjules commented on Dec 17, 2015

    @misterdjules
    misterdjules
    on Dec 17, 2015
    More actions

    Fixed in v4.x-staging with 25cded4, v0.12-staging with 16417cc, v0.10-staging with 9cae9b2 and master with 425a354.

  16. rvagg commented on Dec 17, 2015

    @rvagg
    rvagg
    on Dec 17, 2015
    Member
    More actions

    great work @misterdjules! thanks for pushing so hard on this

  17. misterdjules
    added 2 commits that reference this issue on Dec 17, 2015

    domains: fix handling of uncaught exceptions

    This issue will close once commit 34e64e5 is merged into the 'main' branch.
    34e64e5

    domains: fix handling of uncaught exceptions

    This issue will close once commit 88e8d93 is merged into the 'main' branch.
    88e8d93
  18. MylesBorins
    added 2 commits that reference this issue on Feb 11, 2016

    domains: fix handling of uncaught exceptions

    This issue will close once commit 563c359 is merged into the 'main' branch.
    563c359

    domains: fix handling of uncaught exceptions

    This issue will close once commit 018e4e0 is merged into the 'main' branch.
    018e4e0
  19. priyavivek1 commented on Mar 21, 2016

    @priyavivek1
    priyavivek1
    on Mar 21, 2016
    More actions

    @misterdjules : Which version of 0.10.x is this fixed in..

  20. misterdjules commented on Mar 21, 2016

    @misterdjules
    misterdjules
    on Mar 21, 2016
    More actions

    @priyavivek1 v0.10.43.

  21. scovetta
    added a commit that references this issue on Apr 2, 2016

    domains: fix handling of uncaught exceptions

    This issue will close once commit 3a5eb84 is merged into the 'master' branch.
    3a5eb84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.domainIssues and PRs related to the domain subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.