Changeset 251879 in webkit


Ignore:
Timestamp:
Oct 31, 2019 2:32:29 PM (5 years ago)
Author:
Alan Coon
Message:

Cherry-pick r251304. rdar://problem/56763315

[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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251304 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-608.3.10.0-branch/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608.3.10.0-branch/Source/WebKit/ChangeLog

    r251141 r251879  
     12019-10-31  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r251304. rdar://problem/56763315
     4
     5    [iOS] "Unexpectedly Resumed" process assertion may cause us to get terminated
     6    https://bugs.webkit.org/show_bug.cgi?id=203046
     7    <rdar://problem/56179592>
     8   
     9    Reviewed by Geoffrey Garen.
     10   
     11    This patch implements the following to avoid getting terminated:
     12    1. Schedule the task to release the assertion on a background thread instead of
     13       the main thread so that we end up releasing the task even if the main thread
     14       is somehow hung.
     15    2. Add an invalidation handler to the process assertion which releases the assertion
     16       upon expiration.
     17   
     18    * UIProcess/Cocoa/WebProcessProxyCocoa.mm:
     19    (WebKit::WebProcessProxy::processWasUnexpectedlyUnsuspended):
     20    * WebProcess/WebProcess.cpp:
     21    (WebKit::WebProcess::processDidResume):
     22    * WebProcess/WebProcess.h:
     23    * WebProcess/cocoa/WebProcessCocoa.mm:
     24    (WebKit::WebProcess::processTaskStateDidChange):
     25   
     26   
     27    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251304 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     28
     29    2019-10-18  Chris Dumez  <cdumez@apple.com>
     30
     31            [iOS] "Unexpectedly Resumed" process assertion may cause us to get terminated
     32            https://bugs.webkit.org/show_bug.cgi?id=203046
     33            <rdar://problem/56179592>
     34
     35            Reviewed by Geoffrey Garen.
     36
     37            This patch implements the following to avoid getting terminated:
     38            1. Schedule the task to release the assertion on a background thread instead of
     39               the main thread so that we end up releasing the task even if the main thread
     40               is somehow hung.
     41            2. Add an invalidation handler to the process assertion which releases the assertion
     42               upon expiration.
     43
     44            * UIProcess/Cocoa/WebProcessProxyCocoa.mm:
     45            (WebKit::WebProcessProxy::processWasUnexpectedlyUnsuspended):
     46            * WebProcess/WebProcess.cpp:
     47            (WebKit::WebProcess::processDidResume):
     48            * WebProcess/WebProcess.h:
     49            * WebProcess/cocoa/WebProcessCocoa.mm:
     50            (WebKit::WebProcess::processTaskStateDidChange):
     51
    1522019-10-15  Alan Coon  <alancoon@apple.com>
    253
  • branches/safari-608.3.10.0-branch/Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm

    r250530 r251879  
    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    }
  • branches/safari-608.3.10.0-branch/Source/WebKit/WebProcess/WebProcess.cpp

    r250530 r251879  
    16351635    SQLiteDatabase::setIsDatabaseOpeningForbidden(false);
    16361636    accessibilityProcessSuspendedNotification(false);
     1637    {
     1638        LockHolder holder(m_unexpectedlyResumedUIAssertionLock);
     1639        m_unexpectedlyResumedUIAssertion = nullptr;
     1640    }
    16371641#endif
    16381642
  • branches/safari-608.3.10.0-branch/Source/WebKit/WebProcess/WebProcess.h

    r250530 r251879  
    6363#if PLATFORM(IOS_FAMILY)
    6464#include "ProcessTaskStateObserver.h"
     65OBJC_CLASS BKSProcessAssertion;
    6566#endif
    6667
     
    531532    WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
    532533    Ref<ProcessTaskStateObserver> m_taskStateObserver;
     534    Lock m_unexpectedlyResumedUIAssertionLock;
     535    RetainPtr<BKSProcessAssertion> m_unexpectedlyResumedUIAssertion;
    533536#endif
    534537
  • branches/safari-608.3.10.0-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r250826 r251879  
    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.