Closed Bug 1663941 Opened 4 years ago Closed 4 years ago

ResourceWatcher can call onAvailable callbacks with an empty array of resources

Categories

(DevTools :: Framework, task, P3)

task

Tracking

(firefox82 fixed)

RESOLVED FIXED
82 Branch
Tracking Status
firefox82 --- fixed

People

(Reporter: jdescottes, Assigned: jdescottes)

References

Details

Attachments

(2 files)

After Bug 1660268, the resource watcher might call onResourceAvailable without any resource because of cached resources:

  async _forwardCachedResources(resourceTypes, onAvailable) {
    await onAvailable(
      this._cache.filter(resource =>
        resourceTypes.includes(resource.resourceType)
      )
    );
  }

If the cache doesn't contain any resource matching the provided types, onAvailable is called with an empty array.

This should not really be an issue for production code, as we usually loop on resources before doing anything. But it still might be surprising when writing less critical code (eg test helpers).

I know I stumbled on it while updating our waitForResourceOnce helper and it took me some time to investigate.

Oh yes, I saw that, and a similar things is happening on the server side if there is no cached/existing resources.

For example, here:
https://searchfox.org/mozilla-central/source/devtools/server/actors/resources/console-messages.js#73-88
if messages is empty, we will still emit an available event. We should probably avoid emitting the rdp event from the target and watcher methods.

Assignee: nobody → jdescottes
Status: NEW → ASSIGNED

(In reply to Alexandre Poirot [:ochameau] from comment #2)

For example, here:
https://searchfox.org/mozilla-central/source/devtools/server/actors/resources/console-messages.js#73-88
if messages is empty, we will still emit an available event. We should probably avoid emitting the rdp event from the target and watcher methods.

Oh thanks for the info, I'll try to go over the server side resources as well!

Pushed by jdescottes@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7ca10521eee1 Do not call ResourceWatcher onAvailable callback with empty arrays of ressources r=ochameau https://hg.mozilla.org/integration/autoland/rev/e9d1bafa8602 Do not call onAvailable if cached server resources are empty r=ochameau
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: