⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 252712 in webkit


Ignore:
Timestamp:
Nov 20, 2019, 3:01:40 PM (7 years ago)
Author:
Chris Dumez
Message:

[iOS] Make sure WebContent process does not get suspended while it is holding a process assertion for the UIProcess
https://bugs.webkit.org/show_bug.cgi?id=204418

Reviewed by Jer Noble.

Make sure WebContent process does not get suspended while it is holding a process assertion for the UIProcess. We
see this happening in sysdiagnoses, and it means the system ends up killing the WebContent process because it leaked
a process assertion.

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

(WebKit::WebProcess::processTaskStateDidChange):
(WebKit::WebProcess::releaseProcessWasResumedAssertions):

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r252702 r252712  
     12019-11-20  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Make sure WebContent process does not get suspended while it is holding a process assertion for the UIProcess
     4        https://bugs.webkit.org/show_bug.cgi?id=204418
     5
     6        Reviewed by Jer Noble.
     7
     8        Make sure WebContent process does not get suspended while it is holding a process assertion for the UIProcess. We
     9        see this happening in sysdiagnoses, and it means the system ends up killing the WebContent process because it leaked
     10        a process assertion.
     11
     12        * WebProcess/WebProcess.h:
     13        * WebProcess/cocoa/WebProcessCocoa.mm:
     14        (WebKit::WebProcess::processTaskStateDidChange):
     15        (WebKit::WebProcess::releaseProcessWasResumedAssertions):
     16
    1172019-11-19  Brian Burg  <bburg@apple.com>
    218
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r252636 r252712  
    465465    bool shouldFreezeOnSuspension() const;
    466466    void updateFreezerStatus();
     467
     468    void releaseProcessWasResumedAssertions();
    467469#endif
    468470
     
    543545    WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
    544546    RefPtr<ProcessTaskStateObserver> m_taskStateObserver;
    545     Lock m_processWasResumedUIAssertionLock;
     547    Lock m_processWasResumedAssertionsLock;
    546548    RetainPtr<BKSProcessAssertion> m_processWasResumedUIAssertion;
     549    RetainPtr<BKSProcessAssertion> m_processWasResumedOwnAssertion;
    547550#endif
    548551
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r252636 r252712  
    301301        return;
    302302
    303     LockHolder holder(m_processWasResumedUIAssertionLock);
    304     if (m_processWasResumedUIAssertion)
     303    LockHolder holder(m_processWasResumedAssertionsLock);
     304    if (m_processWasResumedUIAssertion && m_processWasResumedOwnAssertion)
    305305        return;
    306306
     
    308308    // to ensure that it too is awakened.
    309309    RELEASE_LOG(ProcessSuspension, "%p - WebProcess::processTaskStateChanged() Taking 'WebProcess was resumed' assertion on behalf on UIProcess", this);
    310     m_processWasResumedUIAssertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:parentProcessConnection()->remoteProcessID() flags:BKSProcessAssertionPreventTaskSuspend reason:BKSProcessAssertionReasonFinishTask name:@"WebProcess was resumed" withHandler:nil]);
    311 
     310    m_processWasResumedUIAssertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:parentProcessConnection()->remoteProcessID() flags:BKSProcessAssertionPreventTaskSuspend reason:BKSProcessAssertionReasonFinishTask name:@"WebProcess was resumed" withHandler:^(BOOL acquired) {
     311        if (!acquired)
     312            RELEASE_LOG_ERROR(ProcessSuspension, "%p - WebProcess::processTaskStateDidChange() failed to take 'WebProcess was resumed' assertion for parent process", this);
     313    }]);
    312314    m_processWasResumedUIAssertion.get().invalidationHandler = [this] {
    313         LockHolder holder(m_processWasResumedUIAssertionLock);
    314         RELEASE_LOG(ProcessSuspension, "%p - WebProcess::processTaskStateChanged() Releasing 'WebProcess was resumed' assertion on behalf on UIProcess due invalidation", this);
     315        RELEASE_LOG_ERROR(ProcessSuspension, "%p - WebProcess::processTaskStateChanged() Releasing 'WebProcess was resumed' assertion on behalf on UIProcess due to invalidation", this);
     316        releaseProcessWasResumedAssertions();
     317    };
     318    m_processWasResumedOwnAssertion = adoptNS([[BKSProcessAssertion alloc] initWithPID:getpid() flags:BKSProcessAssertionPreventTaskSuspend reason:BKSProcessAssertionReasonFinishTask name:@"WebProcess was resumed" withHandler:^(BOOL acquired) {
     319        if (!acquired)
     320            RELEASE_LOG_ERROR(ProcessSuspension, "%p - WebProcess::processTaskStateDidChange() failed to take 'WebProcess was resumed' assertion for WebContent process", this);
     321    }]);
     322    m_processWasResumedOwnAssertion.get().invalidationHandler = [this] {
     323        RELEASE_LOG_ERROR(ProcessSuspension, "%p - WebProcess::processTaskStateChanged() Releasing 'WebProcess was resumed' assertion on behalf on WebContent process due to invalidation", this);
     324        releaseProcessWasResumedAssertions();
     325    };
     326
     327    parentProcessConnection()->sendWithAsyncReply(Messages::WebProcessProxy::ProcessWasResumed(), [this] {
     328        RELEASE_LOG(ProcessSuspension, "%p - WebProcess::processTaskStateDidChange() Parent process handled ProcessWasResumed IPC, releasing our assertions", this);
     329        releaseProcessWasResumedAssertions();
     330    });
     331}
     332
     333void WebProcess::releaseProcessWasResumedAssertions()
     334{
     335    LockHolder holder(m_processWasResumedAssertionsLock);
     336    if (m_processWasResumedUIAssertion) {
     337        RELEASE_LOG(ProcessSuspension, "%p - WebProcess::releaseProcessWasResumedAssertions() Releasing parent process 'WebProcess was resumed' assertion", this);
    315338        [m_processWasResumedUIAssertion invalidate];
    316339        m_processWasResumedUIAssertion = nullptr;
    317     };
    318 
    319     // This will cause the parent process to send a ParentProcessDidHandleProcessWasResumed IPC back, so that we can release our assertion on its behalf.
    320     parentProcessConnection()->sendWithAsyncReply(Messages::WebProcessProxy::ProcessWasResumed(), [this] {
    321         LockHolder holder(m_processWasResumedUIAssertionLock);
    322         ASSERT(m_processWasResumedUIAssertion);
    323         RELEASE_LOG(ProcessSuspension, "%p - WebProcess::parentProcessDidHandleProcessWasResumed() Releasing 'WebProcess was resumed' assertion on behalf on UIProcess", this);
    324         [m_processWasResumedUIAssertion invalidate];
    325         m_processWasResumedUIAssertion = nullptr;
    326     });
     340    }
     341    if (m_processWasResumedOwnAssertion) {
     342        RELEASE_LOG(ProcessSuspension, "%p - WebProcess::releaseProcessWasResumedAssertions() Releasing WebContent process 'WebProcess was resumed' assertion", this);
     343        [m_processWasResumedOwnAssertion invalidate];
     344        m_processWasResumedOwnAssertion = nullptr;
     345    }
    327346}
    328347
Note: See TracChangeset for help on using the changeset viewer.