Changeset 251304 in webkit


Ignore:
Timestamp:
Oct 18, 2019 3:45:42 PM (5 years ago)
Author:
Chris Dumez
Message:

[iOS] "Unexpectedly Resumed" process assertion may cause us to get terminated
https://bugs.webkit.org/show_bug.cgi?id=203046
<rdar://problem/56179592>

Reviewed by Geoffrey Garen.

This patch implements the following to avoid getting terminated:

  1. Schedule the task to release the assertion on a background thread instead of the main thread so that we end up releasing the task even if the main thread is somehow hung.
  2. Add an invalidation handler to the process assertion which releases the assertion upon expiration.
  • UIProcess/Cocoa/WebProcessProxyCocoa.mm:

(WebKit::WebProcessProxy::processWasUnexpectedlyUnsuspended):

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::processDidResume):

  • WebProcess/WebProcess.h:
  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::processTaskStateDidChange):

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r251298 r251304  
     12019-10-18  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] "Unexpectedly Resumed" process assertion may cause us to get terminated
     4        https://bugs.webkit.org/show_bug.cgi?id=203046
     5        <rdar://problem/56179592>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        This patch implements the following to avoid getting terminated:
     10        1. Schedule the task to release the assertion on a background thread instead of
     11           the main thread so that we end up releasing the task even if the main thread
     12           is somehow hung.
     13        2. Add an invalidation handler to the process assertion which releases the assertion
     14           upon expiration.
     15
     16        * UIProcess/Cocoa/WebProcessProxyCocoa.mm:
     17        (WebKit::WebProcessProxy::processWasUnexpectedlyUnsuspended):
     18        * WebProcess/WebProcess.cpp:
     19        (WebKit::WebProcess::processDidResume):
     20        * WebProcess/WebProcess.h:
     21        * WebProcess/cocoa/WebProcessCocoa.mm:
     22        (WebKit::WebProcess::processTaskStateDidChange):
     23
    1242019-10-18  Jer Noble  <jer.noble@apple.com>
    225
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm

    r250428 r251304  
    195195    if (m_throttler.shouldBeRunnable()) {
    196196        // The process becoming unsuspended was not unexpected; it likely was notified of its running state
    197         // before receiving a procsessDidResume() message from the UIProcess.
     197        // before receiving a processDidResume() message from the UIProcess.
    198198        return;
    199199    }
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r251220 r251304  
    15391539    SQLiteDatabase::setIsDatabaseOpeningForbidden(false);
    15401540    accessibilityProcessSuspendedNotification(false);
     1541    {
     1542        LockHolder holder(m_unexpectedlyResumedUIAssertionLock);
     1543        m_unexpectedlyResumedUIAssertion = nullptr;
     1544    }
    15411545#endif
    15421546
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r251220 r251304  
    6666#if PLATFORM(IOS_FAMILY)
    6767#include "ProcessTaskStateObserver.h"
     68OBJC_CLASS BKSProcessAssertion;
    6869#endif
    6970
     
    535536    WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
    536537    Ref<ProcessTaskStateObserver> m_taskStateObserver;
     538    Lock m_unexpectedlyResumedUIAssertionLock;
     539    RetainPtr<BKSProcessAssertion> m_unexpectedlyResumedUIAssertion;
    537540#endif
    538541
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r250723 r251304  
    312312        return;
    313313
     314    LockHolder holder(m_unexpectedlyResumedUIAssertionLock);
     315    if (m_unexpectedlyResumedUIAssertion)
     316        return;
     317
    314318    // We were awakened from suspension unexpectedly. Notify the WebProcessProxy, but take a process assertion on our parent PID
    315319    // to ensure that it too is awakened.
    316 
    317     auto uiProcessAssertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:parentProcessConnection()->remoteProcessID() flags:BKSProcessAssertionPreventTaskSuspend reason:BKSProcessAssertionReasonFinishTask name:@"Unexpectedly resumed" withHandler:nil]);
     320    m_unexpectedlyResumedUIAssertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:parentProcessConnection()->remoteProcessID() flags:BKSProcessAssertionPreventTaskSuspend reason:BKSProcessAssertionReasonFinishTask name:@"Unexpectedly resumed" withHandler:nil]);
     321
     322    auto releaseAssertion = [this] {
     323        LockHolder holder(m_unexpectedlyResumedUIAssertionLock);
     324        if (!m_unexpectedlyResumedUIAssertion)
     325            return;
     326
     327        [m_unexpectedlyResumedUIAssertion invalidate];
     328        m_unexpectedlyResumedUIAssertion = nullptr;
     329    };
     330
     331    m_unexpectedlyResumedUIAssertion.get().invalidationHandler = releaseAssertion;
    318332    parentProcessConnection()->send(Messages::WebProcessProxy::ProcessWasUnexpectedlyUnsuspended(), 0);
    319     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), [assertion = WTFMove(uiProcessAssertion)] { [assertion invalidate]; });
     333    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), releaseAssertion);
    320334}
    321335#endif
Note: See TracChangeset for help on using the changeset viewer.