Open Bug 1861743 Opened 2 years ago Updated 2 years ago

Detect cyclic dependency with promises and reaction records, and warn it

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: arai, Unassigned)

References

(Blocks 1 open bug)

Details

Bug 1857882 is caused by cyclic dependency around promise, reaction record, and related tasks.

For promise and reactions, the dependencies are represented directly in the references in the object's slots, and we could detect cyclic dependency automatically.
(possibly with pref switch, given this can be heavy operation)

Here's simple case:

In the following case, the await o.prop inside the func is waiting on the func's promise, which never resolves because it depends on await o.prop itself.

async function func(p) {
  var o = await p;

  await o.prop;
}

let resolve;
let p = new Promise(r => resolve = r);

let funcPromise = func(p);

resolve({prop: funcPromise});

In this case, the async function's reaction record is added into the funcPromise, and there's clear cycle.
so, we can check the cycle at the point of await (after adding reaction).

I'm not yet sure if this approach works for more complex case tho, if it works, this should improve the debugging experience around promise-related bug

Type: task → enhancement
You need to log in before you can comment on or make changes to this bug.