Title: [291137] trunk/Source/WebKit
Revision
291137
Author
[email protected]
Date
2022-03-10 16:28:03 -0800 (Thu, 10 Mar 2022)

Log Message

[macOS] WebContent processes crash with XPC_EXIT_REASON_SIGTERM_TIMEOUT when logging out
https://bugs.webkit.org/show_bug.cgi?id=237398
<rdar://88940229>

Reviewed by Alexey Proskuryakov.

Because we don't use RunningBoard on macOS, we leak an OS transaction to control the lifetime of our XPC
services ourselves. However, one of the side effects of leaking this transaction is that the default SIGTERM
handler doesn't cleanly exit our XPC services when logging out or rebooting. This led to crashes with
XPC_EXIT_REASON_SIGTERM_TIMEOUT as termination reason (rdar://88940229).

To address the issue, we now set our own SIGTERM handler that calls _exit(0) to exit cleanly. In the future,
we should likely adopt RunningBoard on macOS and control our lifetime via process assertions instead of
leaking this OS transaction.

* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h:
(WebKit::XPCServiceInitializer):
* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
(WebKit::setOSTransaction):
(WebKit::XPCServiceExit):
(WebKit::osTransaction): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291136 => 291137)


--- trunk/Source/WebKit/ChangeLog	2022-03-11 00:15:39 UTC (rev 291136)
+++ trunk/Source/WebKit/ChangeLog	2022-03-11 00:28:03 UTC (rev 291137)
@@ -1,3 +1,27 @@
+2022-03-10  Chris Dumez  <[email protected]>
+
+        [macOS] WebContent processes crash with XPC_EXIT_REASON_SIGTERM_TIMEOUT when logging out
+        https://bugs.webkit.org/show_bug.cgi?id=237398
+        <rdar://88940229>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Because we don't use RunningBoard on macOS, we leak an OS transaction to control the lifetime of our XPC
+        services ourselves. However, one of the side effects of leaking this transaction is that the default SIGTERM
+        handler doesn't cleanly exit our XPC services when logging out or rebooting. This led to crashes with
+        XPC_EXIT_REASON_SIGTERM_TIMEOUT as termination reason (rdar://88940229).
+
+        To address the issue, we now set our own SIGTERM handler that calls _exit(0) to exit cleanly. In the future,
+        we should likely adopt RunningBoard on macOS and control our lifetime via process assertions instead of
+        leaking this OS transaction.
+
+        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h:
+        (WebKit::XPCServiceInitializer):
+        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
+        (WebKit::setOSTransaction):
+        (WebKit::XPCServiceExit):
+        (WebKit::osTransaction): Deleted.
+
 2022-03-10  Wenson Hsieh  <[email protected]>
 
         [iOS] Add support for -[UITextInput addTextAlternatives:] on WKContentView

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h (291136 => 291137)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h	2022-03-11 00:15:39 UTC (rev 291136)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.h	2022-03-11 00:28:03 UTC (rev 291137)
@@ -82,7 +82,7 @@
 }
 
 #if PLATFORM(MAC)
-OSObjectPtr<os_transaction_t>& osTransaction();
+void setOSTransaction(OSObjectPtr<os_transaction_t>&&);
 #endif
 
 template<typename XPCServiceType, typename XPCServiceInitializerDelegateType>
@@ -113,7 +113,7 @@
     // so ensure that we have an outstanding transaction here. This is not needed on iOS because
     // the UIProcess takes process assertions on behalf of its child processes.
 #if PLATFORM(MAC)
-    osTransaction() = adoptOSObject(os_transaction_create("WebKit XPC Service"));
+    setOSTransaction(adoptOSObject(os_transaction_create("WebKit XPC Service")));
 #endif
 
     InitializeWebKit2();

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm (291136 => 291137)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm	2022-03-11 00:15:39 UTC (rev 291136)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm	2022-03-11 00:28:03 UTC (rev 291137)
@@ -29,6 +29,7 @@
 #import "SandboxUtilities.h"
 #import "XPCServiceEntryPoint.h"
 #import <WebCore/ProcessIdentifier.h>
+#import <signal.h>
 #import <wtf/cocoa/Entitlements.h>
 #import <wtf/spi/darwin/SandboxSPI.h>
 #import <wtf/text/StringToIntegerConversion.h>
@@ -159,10 +160,24 @@
 }
 
 #if PLATFORM(MAC)
-OSObjectPtr<os_transaction_t>& osTransaction()
+void setOSTransaction(OSObjectPtr<os_transaction_t>&& transaction)
 {
-    static NeverDestroyed<OSObjectPtr<os_transaction_t>> transaction;
-    return transaction.get();
+    static NeverDestroyed<OSObjectPtr<os_transaction_t>> globalTransaction;
+
+    // Because we don't use RunningBoard on macOS, we leak an OS transaction to control the lifetime of our XPC
+    // services ourselves. However, one of the side effects of leaking this transaction is that the default SIGTERM
+    // handler doesn't cleanly exit our XPC services when logging out or rebooting. This led to crashes with
+    // XPC_EXIT_REASON_SIGTERM_TIMEOUT as termination reason (rdar://88940229). To address the issue, we now set our
+    // own SIGTERM handler that calls _exit(0). In the future, we should likely adopt RunningBoard on macOS and
+    // control our lifetime via process assertions instead of leaking this OS transaction.
+    static std::once_flag onceKey;
+    std::call_once(onceKey, [] {
+        signal(SIGTERM, [](int) {
+            _exit(0);
+        });
+    });
+
+    globalTransaction.get() = WTFMove(transaction);
 }
 #endif
 
@@ -172,7 +187,7 @@
     priorityBoostMessage = nullptr;
 
 #if PLATFORM(MAC)
-    osTransaction() = nullptr;
+    setOSTransaction(nullptr);
 #endif
 
     xpc_transaction_exit_clean();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to