Open Bug 2005554 Opened 8 months ago Updated 7 months ago

flushQueuedInitialTasks can block the main thread and still miss additional tasks

Categories

(Data Platform and Tools :: Glean: SDK, defect, P1)

defect

Tracking

(Not tracked)

People

(Reporter: janerik, Assigned: janerik)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

We currently use a dispatcher to delay certain metric/ping methods.
This is to avoid calling into libxul (where the glean-core functions are), as that itself might cause a libxul load. We don't want that load until Gecko itself does it (and Glean is initialized).

However the current implementation is buggy:

  1. While asked to queue things (queueInitialTasks=true) we append tasks to a concurrent queue
  2. On init we call flushQueuedInitialTasks, which
    • locks the dispatcher
    • copies tasks from the queue and clears it
    • runs each task
    • sets flushQueuedInitialTasks=false
  3. Continues with work

Any task that tries to queue during step 2, just after the dispatcher is locked, gets blocked. When it unlocks it adds to the queue. The task stays there and is never executed.
This can lose tasks, while also blocking the calling thread trying to enqueue a task.

Visible in this profile: https://share.firefox.dev/4427Ekt

  1. setEnabled is called
  2. DelayedTaskQueue.launch is called
  3. this causes an art::Monitor::lock() call, which blocks.
Assignee: nobody → jrediger
Priority: P3 → P1
See Also: → 2003090
Whiteboard: [telemetry:glean-rs:m?]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: