LayerTreeHost construction race condition fix #1517
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes race condition happening during LayerTreeHost construction The problem is seen with Process Swap On Cross-Site Navigation enabled.
The race condition happens during LayerTreeHost construction. The scenario is:
on THREAD_A (main thread) LayerTreeHost constructor starts; it first creates AcceleratedSurfaceLibWPE, then ThreadedCompositor
ThreadedCompositor constructor creates run loop (m_compositingRunLoop), executes & synchronously waits for initialization task on the run loop. This task calls m_client.nativeSurfaceHandleForCompositing() on THREAD_B (compositing thread) and this ends up calling AcceleratedSurfaceLibWPE::initialize() Note: at this point, LayerTreeHost constructor hasn't set LayerTreeHost::m_compositor value yet
still on THREAD_B, AcceleratedSurfaceLibWPE::initialize connects backend events (wpe_renderer_backend_egl_target_set_client). And sometimes we get first frame_complete event quickly (I've only seen that with PSON enabled). The handler for frame_complete is already registered, and it calls surface.m_client.frameComplete(). And LayerTreeHost::frameComplete() calls 'm_compositor->frameComplete()', but this requires THREAD_A to already have set m_compositor value in ThreadedCompositor constructor, and some memory barrier between threads A & B. So m_compositor can be null here, which causes SIGSEGV.
The proposed fix introduces additional 'LayerTreeHost::initialized' atomic bool which enables to prevent this case and adds memory barrier (via atomic_bool load/store) between threads.
ca3045d