Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domains on rejected promises in unhandledRejection handler #29051

Closed
ORESoftware opened this issue Aug 8, 2019 · 14 comments
Closed

Domains on rejected promises in unhandledRejection handler #29051

ORESoftware opened this issue Aug 8, 2019 · 14 comments
Labels
domain Issues and PRs related to the domain subsystem. promises Issues and PRs related to ECMAScript promises.

Comments

@ORESoftware
Copy link
Contributor

ORESoftware commented Aug 8, 2019

I am on Node.js version 9-12. This code was working on 9,10,11, but changed with version 12:

  process.on('unhandledRejection', (e, p) => {
    
    let d = null;
    
    if (p.domain && p.domain.havenUuid) {
      d = p.domain;   
    } else if (process.domain && process.domain.havenUuid) {
      d = process.domain;
    }

     // more code here can be ignored

});

What I do is mark a domain with a property "havenUuid", if it has that property, it's a domain that I created/control.

What's happening starting with version 12 is that rejected promises no longer have an associated domain property attached to them when they reach the unhandledRejection handler. Is this an expected change in version 12? Because relevant domains were attached to rejected promises in versions 9, 10, 11, etc.

I am guessing that domains are no longer attached to rejected promises because doing so introduced bugs or something? I assume it's not a bug that domains are no longer attached to rejected promises in unhandledRejection handlers, but who knows.

@Trott Trott added domain Issues and PRs related to the domain subsystem. promises Issues and PRs related to ECMAScript promises. labels Aug 8, 2019
@ORESoftware
Copy link
Contributor Author

ORESoftware commented Aug 8, 2019

Here is a repro:

'use strict';

const Domain = require('domain');
const d = Domain.create();

process.once('unhandledRejection', (r, p) => {
  console.log(p.domain);  // on versions 9, 10, 11, p.domain is defined, on version 12, it is *undefined*
});

d.once('error', () => {
  console.log('domain caught');
});


d.run(() => {
  Promise.resolve(null).then(() => {
    throw 'foo';
  });
});

@ORESoftware
Copy link
Contributor Author

ORESoftware commented Aug 8, 2019

I did some more research, p.domain is not defined starting with 12.0.0, so I assume a deliberate decision to omit it, any docs on this? In the release notes, I don't see anything in 12.0.0 which mentions this change: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#2019-04-23-version-1200-current-bethgriggs

here was my original issue: nodejs/help#2110

@ORESoftware
Copy link
Contributor Author

@benjamingr you know anything about this?

@devsnek
Copy link
Member

devsnek commented Aug 10, 2019

probably related to the missing async context in #28317

@ORESoftware
Copy link
Contributor Author

ORESoftware commented Aug 12, 2019

@devsnek is there a way to demonstrate that the two problems are related?

@devsnek
Copy link
Member

devsnek commented Aug 12, 2019

@ORESoftware domain uses async_hooks, so if the context is wrong for async hooks, it would be wrong for domain too.

@ORESoftware
Copy link
Contributor Author

ORESoftware commented Aug 17, 2019

do you think this could get fixed before version 13? I could try to help

@benjamingr
Copy link
Member

Sure, probably look at Anna's PR for adding it in. Honestly I don't use domains and don't know the code well enough. CC @addaleax

@ORESoftware
Copy link
Contributor Author

@addaleax any idea how to fix?

@ORESoftware
Copy link
Contributor Author

just making a bump to ensure it gets looked at ty

@devsnek
Copy link
Member

devsnek commented Feb 2, 2020

#26794

@ORESoftware
Copy link
Contributor Author

ORESoftware commented Mar 21, 2020

thanks all, just tried this on Node.js 13.11, and still broken:

'use strict';

const Domain = require('domain');
const d = Domain.create();

process.once('unhandledRejection', (r, p) => {
  console.log(p.domain);  // on versions 9, 10, 11, p.domain is defined, on version 12, it is *undefined*
});

d.once('error', () => {
  console.log('domain caught');
});


d.run(() => {
  Promise.resolve(null).then(() => {
    throw 'foo';
  });
});

I got "undefined" logged, but I am looking for a domain instance to get logged, as it used to be in version 9,10,11. Starting with version 12.0, it stopped working as before.

@benjamingr
Copy link
Member

I think I fixed this pretty recently for the REPL PR can someone check?

@ORESoftware
Copy link
Contributor Author

@benjamingr this is looking good in Node v15.3.0, according to my testing, glad to see it fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain Issues and PRs related to the domain subsystem. promises Issues and PRs related to ECMAScript promises.
Projects
None yet
Development

No branches or pull requests

4 participants