archives

« Bugzilla Issues Index

#2995 — 15.2.5.2.3 UpdateLinkSetOnLoad 5 startingLoad can be undefined


This has been a very hard bug to track down that's caused loading stalling for quite some time in roughly once every 30 runs of the loader polyfill test cases.

The scenario happens when updateLinkSetOnLoad triggers linking of LinkSets one by one.

Basically, it is possible for a LinkSet to be cleared of loads through finishLoad, where the linkSet itself has not resolved yet, making the linkSet startingLoad in updateLinkSetOnLoad undefined, resolving the linkSet to resolve to undefined, resulting in LoadModule returning an undefined load record.

I've described the test case below. There is certainly a simpler example than this, but this is the one that I've actually been able to catch.

Consider a tree where A depends on D, B depends on A, C depends on B.

The Linksets when almost fully loaded look like:

load record: linkSets
A: {A D} {C B A D} {C A D}
B: {B A D} {C B A D}
C: {C B A D}
D: {A D} {C B A D} {B A D}

A, B, C have all called LoadSucceeded in the above, and UpdateLinkSetOnLoad. That is, we are just waiting on D to finish the load.

D hits LoadSucceeded, and has no dependencies to contribute.

It then runs UpdateLinkSetOnLoad for each of its linksets, cloning this list before running it.

It first runs UpdateLinkSetOnLoad for the linkset {A D} resulting in this linkset linking and removing its records from the list through a finishLoad call for both A and D, thus we now have:

load record: linkSets
A: {C B} {C}
B: {B} {C B}
C: {C B}
D: {C B} {B}

We now run UpdateLinkSetOnLoad for {C B} resulting in calling finishLoad for both C and B. We have now cleared all the linksets.

Finally, we get to our last linkSet in the cloned list to run UpdateLinkSetOnLoad, which was {B} above, but it has been cleared already since B has finished loading.

But LinkSets resolve to their starting load, so we resolve this linkset to undefined.

As a result, System.import("B"), which has run LoadModule, gets an undefined load record back for its promise though AsyncStartLoadPartwayThrough resolving to this linkSet.

---

In terms of a fix, not clearing the first load of a linkSet in finishLoad seems to resolve the issue.

That is, in 15.2.5.2.5 4.a, ensure that load is not the first element of linkSet.[[Loads]] first.

This fix is by no means ideal and it breaks the final assertion in UpdateLinkSetOnLoad that the loads have been cleared.

There is most likely a better fix. As mentioned I'd be happy to assist, just let me what I can do further to help.


A better fix is to store linkSet.startingLoad during createLinkSet, and to use this instead of linkSet.loads[0] in UpdateLinkSetOnLoad.

Note that we should be careful not to try to link an empty linkSet then too.


concerns old module spec.