Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Wrong current zone observed inside Bluebird's then() #921

Closed
vkopyl opened this issue Oct 6, 2017 · 3 comments · Fixed by #1039
Closed

Wrong current zone observed inside Bluebird's then() #921

vkopyl opened this issue Oct 6, 2017 · 3 comments · Fixed by #1039

Comments

@vkopyl
Copy link

vkopyl commented Oct 6, 2017

Hi!

Observing the issue when using bluebird module. Fork a zone 'A' with a bluebird promise in run. Check Zone.current.name in then function. In should be 'A'. Fork a new zone, 'B', check Zone.current in then. Expected 'B', but it still reports 'A'.

(running in Node v6.11.3)

Please check: https://runkit.com/vkopyl/test-bluebird-with-zone-js

require('zone.js/dist/zone-node.js');
const Bluebird = require('bluebird');
require('zone.js/dist/zone-bluebird.min');
Zone[Zone['__symbol__']('bluebird')](Bluebird);

Zone.current.fork({
  name: 'zone_A'
}).run(() => {
  new Bluebird((resolve, reject) => {
    console.log('in promise A: ' + Zone.current.name);
    resolve(1);
  }).then(r => {
    console.log('inside then A: ' + Zone.current.name);
  });
});

Zone.current.fork({
  name: 'zone_B'
}).run(() => {
  new Bluebird((resolve, reject) => {
    console.log('in promise B: ' + Zone.current.name);
    resolve(2);
  }).then(r => {
    console.log('inside then B: ' + Zone.current.name); // expected zone_B, reports zone_A
  });
})
@JiaLiPassion
Copy link
Collaborator

@vkopyl , thank you for reporting the issue, I will check it.

@utf4
Copy link

utf4 commented Dec 27, 2017

I am also observing the same issue. .then is resolving in the wrong zone. In fact every .then is getting resolved to the zone of very first promise. I am getting the same thing below:

Code:

require('zone.js');
const P1 = require('bluebird');

Zone.current.fork({name: 'Zone Fork 1'}).run(() => {
  console.log(`============> Zone Name Outside of Promise 1: ** ${Zone.current.name} **`);
  P1.resolve().then((_record) => {
    console.log(`===============================================================`);
    console.log(`============> Zone Name Inside of Promise 1: ** ${Zone.current.name} **`);
  });
});

Zone.current.fork({name: 'Zone Fork 2'}).run(() => {
  console.log(`============> Zone Name Outside of Promise 2: ** ${Zone.current.name} **`);
  P1.resolve().then((_record) => {
    console.log(`============> Zone Name Inside of Promise 2: ** ${Zone.current.name} **`);
  });
});

Zone.current.fork({name: 'Zone Fork 3'}).run(() => {
  console.log(`============> Zone Name Outside of Promise 3: ** ${Zone.current.name} **`);
  P1.resolve().then((_record) => {
    console.log(`============> Zone Name Inside of Promise 3: ** ${Zone.current.name} **`);
  });
});

Output:

============> Zone Name Outside of Promise 1: ** Zone Fork 1 **
============> Zone Name Outside of Promise 2: ** Zone Fork 2 **
============> Zone Name Outside of Promise 3: ** Zone Fork 3 **
===============================================================
============> Zone Name Inside of Promise 1: ** Zone Fork 1 **
============> Zone Name Inside of Promise 2: ** Zone Fork 1 **
============> Zone Name Inside of Promise 3: ** Zone Fork 1 **

I am still looking how to fix or just to have a workaround.

@JiaLiPassion
Copy link
Collaborator

@vkopyl@furqanaziz , I have fixed this one, please wait for the next release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants