archives

« Bugzilla Issues Index

#2602 — Loader: a Load can be dropped due to a race condition populating [[LinkSets]]


Guy Bedford reports:
> When in ProcessLoadDependencies, RequestLoad is called for each
> dependency, in turn running ProceedToLocate.
>
> This ProceedToLocate therefore runs before we've added the dependency
> load to the linkset with AddLoadToLinkset.
>
> As a result, we can reach the Fetch and Locate hooks before the
> load.linkSets have been populated at all.
>
> The check for load.linkSets.length == 0 then passes, assuming a failed
> load, and the fetch and translate get skipped.

I agree this is a race condition and a bug.

There are several possible fixes. Guy suggests changing the check to test load.[[Status]] rather than load.[[LinkSets]], which seems like the simplest thing.


The race condition is simply caused by the asynchronous nature of promises. So just running ProceedToLocate after a process tick is enough to avoid it.

Since RequestLoad only seems to be called from within ProcessLoadDependencies, it may even make sense to collapse RequestLoad into ProcessLoadDependencies and then run the call to ProceedToLocate after each AddDependencyLoad instead of before.


concerns old module spec.