<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>256278</bug_id>
          
          <creation_ts>2023-05-03 16:00:46 -0700</creation_ts>
          <short_desc>Running API tests often logs &quot;Error while launching com.apple.WebKit.Networking: Connection invalid&quot;</short_desc>
          <delta_ts>2023-05-04 16:38:03 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tools / Tests</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=238080</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Simon Fraser (smfr)">simon.fraser</reporter>
          <assigned_to name="Chris Dumez">cdumez</assigned_to>
          <cc>cdumez</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1952764</commentid>
    <comment_count>0</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-05-03 16:00:46 -0700</bug_when>
    <thetext>Running an API test on macOS (I was launching TestWebKitAPI with `--gtest_filter=TextManipulation.CompleteTextManipulationAddsOverflowHiddenToAvoidBreakingLayout`) often shows:

ERROR: Error while launching com.apple.WebKit.Networking: Connection invalid
/Volumes/Data/Development/system/webkit/OpenSource/Source/WebKit/UIProcess/Launcher/cocoa/ProcessLauncherCocoa.mm(229) : auto WebKit::ProcessLauncher::launchProcess()::(anonymous class)::operator()(xpc_object_t) const

Some logging shows:

ProcessLauncher 0x117059e90 launch process com.apple.WebKit.WebContent
WebProcessProxy 0x143000c00 didFinishLaunching - launcher 0x117059e90
NetworkProcessProxy ctor 0x1170ac110
ProcessLauncher 0x1170b4130 launch process com.apple.WebKit.Networking
NetworkProcessProxy ctor 0x1170ac110 connected
NetworkProcessProxy dtor 0x1170ac110
ProcessLauncher 0x1170b4130 terminateXPCConnection
ProcessLauncher - launch process got error

So we make a NetworkProcessProxy and immediately destroy it. This happens when we lose the last ref to the NetworkProcessProxy here:

  * frame #0: 0x000000012d6ff764 WebKit`WebKit::NetworkProcessProxy::~NetworkProcessProxy(this=0x000000010802c460) at NetworkProcessProxy.cpp:272:5
    frame #1: 0x000000012d6ffb9c WebKit`WebKit::NetworkProcessProxy::~NetworkProcessProxy(this=0x000000010802c460) at NetworkProcessProxy.cpp:271:1
    frame #2: 0x000000012d6ffc20 WebKit`WebKit::NetworkProcessProxy::~NetworkProcessProxy(this=0x000000010802c460) at NetworkProcessProxy.cpp:271:1
    frame #3: 0x000000012e574878 WebKit`WTF::ThreadSafeRefCounted&lt;WebKit::AuxiliaryProcessProxy, (WTF::DestructionThread)2&gt;::deref(this=0x0000000108004c98) const::&apos;lambda&apos;()::operator()() const at ThreadSafeRefCounted.h:115:13
    frame #4: 0x000000012bd60eb0 WebKit`WTF::Detail::CallableWrapper&lt;WTF::ThreadSafeRefCounted&lt;WebKit::AuxiliaryProcessProxy, (WTF::DestructionThread)2&gt;::deref() const::&apos;lambda&apos;(), void&gt;::call(this=0x0000000108004c90) at Function.h:53:39
    frame #5: 0x000000010d4fb3c8 JavaScriptCore`WTF::Function&lt;void ()&gt;::operator()(this=0x000000016fdfd508) const at Function.h:82:35
    frame #6: 0x000000010d559fd0 JavaScriptCore`WTF::ensureOnMainRunLoop(function=0x000000016fdfd508) at MainThread.cpp:74:9
    frame #7: 0x000000012bd60d64 WebKit`WTF::ThreadSafeRefCounted&lt;WebKit::AuxiliaryProcessProxy, (WTF::DestructionThread)2&gt;::deref(this=0x000000010802c468) const at ThreadSafeRefCounted.h:124:13
    frame #8: 0x000000012bd60ce0 WebKit`WebKit::AuxiliaryProcessProxy::deref(this=0x000000010802c460) at AuxiliaryProcessProxy.h:159:48
    frame #9: 0x000000012bd60c7c WebKit`WTF::Ref&lt;WebKit::NetworkProcessProxy, WTF::RawPtrTraits&lt;WebKit::NetworkProcessProxy&gt;&gt;::~Ref(this=0x000000016fdfd5c0) at Ref.h:61:18
    frame #10: 0x000000012bd5a948 WebKit`WTF::Ref&lt;WebKit::NetworkProcessProxy, WTF::RawPtrTraits&lt;WebKit::NetworkProcessProxy&gt;&gt;::~Ref(this=0x000000016fdfd5c0) at Ref.h:55:5
    frame #11: 0x000000012d5b96b0 WebKit`WebKit::WebProcessProxy::didFinishLaunching(WebKit::ProcessLauncher*, IPC::Connection::Identifier)::$_57::operator()(this=0x0000000108001da8) const at WebProcessProxy.cpp:1208:13
    frame #12: 0x000000012d5b95ac WebKit`WTF::Detail::CallableWrapper&lt;WebKit::WebProcessProxy::didFinishLaunching(WebKit::ProcessLauncher*, IPC::Connection::Identifier)::$_57, void&gt;::call(this=0x0000000108001da0) at Function.h:53:39
    frame #13: 0x000000010d4fb3c8 JavaScriptCore`WTF::Function&lt;void ()&gt;::operator()(this=0x000000016fdfd660) const at Function.h:82:35
    frame #14: 0x000000010d5968d8 JavaScriptCore`WTF::RunLoop::performWork(this=0x0000000108010100) at RunLoop.cpp:147:9
    frame #15: 0x000000010d59ada4 JavaScriptCore`WTF::RunLoop::performWork(context=0x0000000108010100) at RunLoopCF.cpp:46:37
    frame #16: 0x0000000183f474c8 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    frame #17: 0x0000000183f4745c CoreFoundation`__CFRunLoopDoSource0 + 176
    frame #18: 0x0000000183f471cc CoreFoundation`__CFRunLoopDoSources0 + 244
    frame #19: 0x0000000183f45dd4 CoreFoundation`__CFRunLoopRun + 828
    frame #20: 0x0000000183f453e4 CoreFoundation`CFRunLoopRunSpecific + 600
    frame #21: 0x0000000184fb0cf8 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
    frame #22: 0x0000000100e69554 TestWebKitAPI`TestWebKitAPI::Util::run(done=0x00006000034c9278) at UtilitiesCocoa.mm:35:9
    frame #23: 0x0000000100e51d20 TestWebKitAPI`-[TestNavigationDelegate waitForDidFinishNavigation](self=0x0000600001feb790, _cmd=&quot;waitForDidFinishNavigation&quot;) at TestNavigationDelegate.mm:140:5
    frame #24: 0x0000000100e53584 TestWebKitAPI`-[WKWebView(self=0x000000014aeb6d90, _cmd=&quot;_test_waitForDidFinishNavigation&quot;) _test_waitForDidFinishNavigation] at TestNavigationDelegate.mm:248:5
    frame #25: 0x0000000100e565e4 TestWebKitAPI`-[WKWebView(self=0x000000014aeb6d90, _cmd=&quot;synchronouslyLoadHTMLString:baseURL:&quot;, html=&quot;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;  &lt;style&gt;    span {      display: inline-block;      width: 28px;      height: 40px;      margin: 0;      word-break: break-all;      font-size: 32px;    }    a {      display: block;      width: 100px;      height: 100px;      overflow: hidden;    }  &lt;/style&gt;&lt;/head&gt;&lt;body&gt;  &lt;a&gt;    &lt;span&gt;A&lt;/span&gt; Hello world  &lt;/a&gt;&lt;/body&gt;&lt;/html&gt;&quot;, url=&quot;file:///Volumes/Data/Development/system/webkit/OpenSource/WebKitBuild/Debug/TestWebKitAPI.resources/&quot;) synchronouslyLoadHTMLString:baseURL:] at TestWKWebView.mm:105:5
    frame #26: 0x0000000100e56658 TestWebKitAPI`-[WKWebView(self=0x000000014aeb6d90, _cmd=&quot;synchronouslyLoadHTMLString:&quot;, html=&quot;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;  &lt;style&gt;    span {      display: inline-block;      width: 28px;      height: 40px;      margin: 0;      word-break: break-all;      font-size: 32px;    }    a {      display: block;      width: 100px;      height: 100px;      overflow: hidden;    }  &lt;/style&gt;&lt;/head&gt;&lt;body&gt;  &lt;a&gt;    &lt;span&gt;A&lt;/span&gt; Hello world  &lt;/a&gt;&lt;/body&gt;&lt;/html&gt;&quot;) synchronouslyLoadHTMLString:] at TestWKWebView.mm:110:5
    frame #27: 0x0000000100b373e4 TestWebKitAPI`TestWebKitAPI::TextManipulation_CompleteTextManipulationAddsOverflowHiddenToAvoidBreakingLayout_Test::TestBody(this=0x00006000036be570) at TextManipulation.mm:3420:5
    frame #28: 0x0000000100f4b6bc TestWebKitAPI`void testing::internal::HandleSehExceptionsInMethodIfSupported&lt;testing::Test, void&gt;(object=0x00006000036be570, method=(actual=0x0000000100eff530 TestWebKitAPI`_ZN7testing4Test8TestBodyEv_vfpthunk_ at gtest.cc:2707:3), location=&quot;the test body&quot;) at gtest.cc:2607:10
    frame #29: 0x0000000100eff25c TestWebKitAPI`void testing::internal::HandleExceptionsInMethodIfSupported&lt;testing::Test, void&gt;(object=0x00006000036be570, method=(actual=0x0000000100eff530 TestWebKitAPI`_ZN7testing4Test8TestBodyEv_vfpthunk_ at gtest.cc:2707:3), location=&quot;the test body&quot;) at gtest.cc:2643:14
    frame #30: 0x0000000100eff190 TestWebKitAPI`testing::Test::Run(this=0x00006000036be570) at gtest.cc:2682:5
    frame #31: 0x0000000100f003e8 TestWebKitAPI`testing::TestInfo::Run(this=0x000000014ae74320) at gtest.cc:2861:11
    frame #32: 0x0000000100f017c0 TestWebKitAPI`testing::TestSuite::Run(this=0x000000014ae6e8e0) at gtest.cc:3015:28
    frame #33: 0x0000000100f0fd04 TestWebKitAPI`testing::internal::UnitTestImpl::RunAllTests(this=0x000000014ae04980) at gtest.cc:5851:44
    frame #34: 0x0000000100f4c098 TestWebKitAPI`bool testing::internal::HandleSehExceptionsInMethodIfSupported&lt;testing::internal::UnitTestImpl, bool&gt;(object=0x000000014ae04980, method=(actual=0x0000000100f0f858 TestWebKitAPI`testing::internal::UnitTestImpl::RunAllTests() at gtest.cc:5742), location=&quot;auxiliary test code (environments or event listeners)&quot;) at gtest.cc:2607:10
    frame #35: 0x0000000100f0f5cc TestWebKitAPI`bool testing::internal::HandleExceptionsInMethodIfSupported&lt;testing::internal::UnitTestImpl, bool&gt;(object=0x000000014ae04980, method=(actual=0x0000000100f0f858 TestWebKitAPI`testing::internal::UnitTestImpl::RunAllTests() at gtest.cc:5742), location=&quot;auxiliary test code (environments or event listeners)&quot;) at gtest.cc:2643:14
    frame #36: 0x0000000100f0f4b0 TestWebKitAPI`testing::UnitTest::Run(this=0x00000001012b5a80) at gtest.cc:5434:10
    frame #37: 0x0000000100571e58 TestWebKitAPI`RUN_ALL_TESTS() at gtest.h:2471:46
    frame #38: 0x0000000100571de4 TestWebKitAPI`TestWebKitAPI::TestsController::run(this=0x00000001012b5268, argc=1, argv=0x000000016fdff590) at TestsController.cpp:89:13
    frame #39: 0x0000000100ed2418 TestWebKitAPI`main(argc=2, argv=0x000000016fdff590) at mainMac.mm:83:62


So no-one retains the NetworkProcessProxy created at:
            NetworkProcessProxy::ensureDefaultNetworkProcess()-&gt;sendXPCEndpointToProcess(*weakThis);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1952771</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-05-03 16:23:11 -0700</bug_when>
    <thetext>&lt;rdar://problem/108866781&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1952773</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2023-05-03 16:27:45 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/13423</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953033</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-05-04 16:38:01 -0700</bug_when>
    <thetext>Committed 263698@main (3d791e9725a5): &lt;https://commits.webkit.org/263698@main&gt;

Reviewed commits have been landed. Closing PR #13423 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>