• Henrik Boström's avatar
    RTCRtpSenderInternal destructor traits ensuring delete on main thread. · a43fb027
    Henrik Boström authored
    The internal class owns AdapterRefs which have to be destructed on the
    main thread. As such, the last reference to the internal class had to
    be freed on the main thread. In flaky cases, when tasks were posted to
    the signaling thread, an operation performed and a task posted back to
    the main thread - the main thread would finish before the signaling
    thread task and the last reference to the internal class would be
    released on the signaling thread, causing DCHECK crashes at
    ~AdapterRef for being on the wrong thread.
    
    With destructor traits, if we are not already on the main thread we
    post to the main thread and delete RTCRtpSenderInternal there.
    
    The TearDown of RTCRtpSenderTest is updated to ensure that any pending
    tasks get a chance to execute, in case the signaling thread was not
    finished yet or else the destructor posted to the main thread does not
    get a chance to execute and the test would flakily leak.
    
    Before this CL: Flake's symptoms could be reproduced by adding a thread
    sleep at RTCRtpSenderInternal::GetStatsOnSignalingThread. After this CL:
    Unable to repro flake. The same applies for the other flaking tests
    based on replaceTrack().
    
    Bug: 827450
    Change-Id: Ib594a53042e441e591ccc2c87ae8012bcb4ec75e
    Reviewed-on: https://chromium-review.googlesource.com/1015002
    Commit-Queue: Henrik Boström <hbos@chromium.org>
    Reviewed-by: default avatarWez <wez@chromium.org>
    Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#553550}
    a43fb027
rtc_rtp_sender_unittest.cc 10.4 KB