Bug 194427

Summary: Add SPI to use networking daemon instead of XPC service
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, dbates, ews-watchlist, ggaren, joepeck, mitz, rniwa, sam, tsavell, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from ews121 for ios-simulator-wk2
none
Patch
none
Patch
none
Patch
none
Patch
none
Archive of layout-test-results from ews106 for mac-highsierra-wk2
none
Archive of layout-test-results from ews125 for ios-simulator-wk2
none
Patch none

Description Alex Christensen 2019-02-07 20:51:48 PST
Add SPI to use networking daemon instead of XPC service
Comment 1 Alex Christensen 2019-02-07 20:56:23 PST
Created attachment 361491 [details]
Patch
Comment 2 Geoffrey Garen 2019-02-07 21:21:00 PST
Comment on attachment 361491 [details]
Patch

r=me
Comment 3 EWS Watchlist 2019-02-08 00:07:40 PST
Comment on attachment 361491 [details]
Patch

Attachment 361491 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/11076179

New failing tests:
imported/w3c/web-platform-tests/webrtc/simplecall.https.html
Comment 4 EWS Watchlist 2019-02-08 00:07:42 PST
Created attachment 361494 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 5 Alex Christensen 2019-02-08 09:14:31 PST
Created attachment 361507 [details]
Patch
Comment 6 Alex Christensen 2019-02-08 09:16:42 PST
Comment on attachment 361507 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=361507&action=review

> Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm:177
> +    xpc_dictionary_set_value(bootstrapMessage.get(), "initialization-message", initializationMessage.get());

I made the initialization message a member of the bootstrap message instead of sending a separate message to reduce the number of messages sent during process launching.
Comment 7 Alex Christensen 2019-02-08 09:18:25 PST
http://trac.webkit.org/r241197
Comment 8 Radar WebKit Bug Importer 2019-02-08 09:19:29 PST
<rdar://problem/47918588>
Comment 9 Truitt Savell 2019-02-08 11:28:46 PST
It looks like https://trac.webkit.org/changeset/241197/webkit 

Has broken iOS Debug https://build.webkit.org/builders/Apple%20iOS%2012%20Simulator%20Debug%20%28Build%29/builds/3331

as well as caused 1 API failure on High Sierra:
https://build.webkit.org/builders/Apple%20High%20Sierra%20Release%20WK2%20%28Tests%29/builds/9384

Failed

    TestWebKitAPI.WebKit.InjectedBundleAppleEvent
        
        /Volumes/Data/slave/highsierra-release/build/Tools/TestWebKitAPI/Tests/WebKit/mac/InjectedBundleAppleEvent.cpp:55
        Expected: (0) != (returnCode), actual: 0 vs 0
Comment 10 Joseph Pecoraro 2019-02-08 12:08:38 PST
Comment on attachment 361507 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=361507&action=review

> Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp:76
> +    case ProcessLauncher::ProcessType::NetworkDaemon:
> +        ASSERT_NOT_REACHED();

I'd expect a `break` here to avoid potential -Wswitch/-Wfallthrough warnings.
Comment 11 Truitt Savell 2019-02-08 13:19:37 PST
Reverted r241197 for reason:

Broke iOS Simulator Debug build and casued 1 API failure on High Sierra

Committed r241205: <https://trac.webkit.org/changeset/241205>
Comment 12 Alex Christensen 2019-02-08 16:05:07 PST
Created attachment 361554 [details]
Patch
Comment 13 Alex Christensen 2019-02-08 16:07:30 PST
Comment on attachment 361554 [details]
Patch

I put the SPI header definitions in the correct sections, moved the __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling, and put the whole "bootstrap" event handler in a std::call_once because it sets the environment that we won't be able to set with the second xpc connection to a daemon.
Comment 14 EWS Watchlist 2019-02-08 16:08:06 PST
Attachment 361554 [details] did not pass style-queue:


ERROR: Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:115:  Misplaced OS version check. Please use a named macro in wtf/Platform.h, wtf/FeatureDefines.h, or an appropriate internal file.  [build/version_check] [5]
ERROR: Source/WTF/wtf/spi/darwin/XPCSPI.h:84:  _xpc_error_key_description is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 2 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 15 Alex Christensen 2019-02-08 17:18:16 PST
I also gave MiniBrowser's sandbox permission to communicate with this new mach service.

http://trac.webkit.org/r241223
Comment 16 Alex Christensen 2019-02-08 23:04:58 PST
http://trac.webkit.org/r241235
Comment 17 Alex Christensen 2019-02-09 00:07:53 PST
My changelog entry for r241235 indicated an API test on Mojave.  It was actually a fix fo the WebKit.InjectedBundleAppleEvent API test on High Sierra, and it seems to have worked.
Comment 18 Daniel Bates 2019-02-09 06:42:01 PST
(In reply to Alex Christensen from comment #17)
> My changelog entry for r241235 indicated an API test on Mojave.  It was
> actually a fix fo the WebKit.InjectedBundleAppleEvent API test on High
> Sierra, and it seems to have worked.

You can fix the ChangeLog. Fix it?
Comment 19 Sam Weinig 2019-02-10 13:03:49 PST
(In reply to Alex Christensen from comment #13)
> Comment on attachment 361554 [details]
> Patch
> 
> I put the SPI header definitions in the correct sections, moved the
> __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> and put the whole "bootstrap" event handler in a std::call_once because it
> sets the environment that we won't be able to set with the second xpc
> connection to a daemon.

I don't think this is correct for the daemon case. If two UIProcesses with different expectations of the networking daemon connect to it, each with different  initialization criteria, this will not yield the right result. For instance, any OverrideLanguages will not be set. I would think you would either need to remove those UIProcess specific settings completely, or make it so multiple daemons could be spawned, one for each initialization criteria set.
Comment 20 Sam Weinig 2019-02-10 13:08:25 PST
(In reply to Sam Weinig from comment #19)
> (In reply to Alex Christensen from comment #13)
> > Comment on attachment 361554 [details]
> > Patch
> > 
> > I put the SPI header definitions in the correct sections, moved the
> > __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> > and put the whole "bootstrap" event handler in a std::call_once because it
> > sets the environment that we won't be able to set with the second xpc
> > connection to a daemon.
> 
> I don't think this is correct for the daemon case. If two UIProcesses with
> different expectations of the networking daemon connect to it, each with
> different  initialization criteria, this will not yield the right result.
> For instance, any OverrideLanguages will not be set. I would think you would
> either need to remove those UIProcess specific settings completely, or make
> it so multiple daemons could be spawned, one for each initialization
> criteria set.

When we initially added the bootstrap message using xpc_connection_set_bootstrap/xpc_copy_bootstrap, it was needed because the actions taken needed to happen before xpc_main() was called. What has changed to make that no longer necessary?
Comment 21 Geoffrey Garen 2019-02-10 13:42:43 PST
> > I put the SPI header definitions in the correct sections, moved the
> > __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> > and put the whole "bootstrap" event handler in a std::call_once because it
> > sets the environment that we won't be able to set with the second xpc
> > connection to a daemon.
> 
> I don't think this is correct for the daemon case. If two UIProcesses with
> different expectations of the networking daemon connect to it, each with
> different  initialization criteria, this will not yield the right result.
> For instance, any OverrideLanguages will not be set. I would think you would
> either need to remove those UIProcess specific settings completely, or make
> it so multiple daemons could be spawned, one for each initialization
> criteria set.

I don't think the OS supports multi-daemon, so we'll need to resolve the UIProcess specific settings.
Comment 22 Alex Christensen 2019-02-11 10:39:20 PST
(In reply to Sam Weinig from comment #19)
> (In reply to Alex Christensen from comment #13)
> > Comment on attachment 361554 [details]
> > Patch
> > 
> > I put the SPI header definitions in the correct sections, moved the
> > __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> > and put the whole "bootstrap" event handler in a std::call_once because it
> > sets the environment that we won't be able to set with the second xpc
> > connection to a daemon.
> 
> I don't think this is correct for the daemon case. If two UIProcesses with
> different expectations of the networking daemon connect to it, each with
> different  initialization criteria, this will not yield the right result.
> For instance, any OverrideLanguages will not be set. I would think you would
> either need to remove those UIProcess specific settings completely, or make
> it so multiple daemons could be spawned, one for each initialization
> criteria set.

I don't think this will be a problem right away because there will only be one client that uses the SPI to use the daemon, and I think its initialization criteria will be the same for each instance.

(In reply to Sam Weinig from comment #20)
> (In reply to Sam Weinig from comment #19)
> > (In reply to Alex Christensen from comment #13)
> > > Comment on attachment 361554 [details]
> > > Patch
> > > 
> > > I put the SPI header definitions in the correct sections, moved the
> > > __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> > > and put the whole "bootstrap" event handler in a std::call_once because it
> > > sets the environment that we won't be able to set with the second xpc
> > > connection to a daemon.
> > 
> > I don't think this is correct for the daemon case. If two UIProcesses with
> > different expectations of the networking daemon connect to it, each with
> > different  initialization criteria, this will not yield the right result.
> > For instance, any OverrideLanguages will not be set. I would think you would
> > either need to remove those UIProcess specific settings completely, or make
> > it so multiple daemons could be spawned, one for each initialization
> > criteria set.
> 
> When we initially added the bootstrap message using
> xpc_connection_set_bootstrap/xpc_copy_bootstrap, it was needed because the
> actions taken needed to happen before xpc_main() was called. What has
> changed to make that no longer necessary?

It seems that the setting of the __APPLEEVENTSSERVICENAME environment variable is only effective if done before calling xpc_main, but the rest seems to work unless I'm missing something.  The part that must be done before xpc_main does not depend on any information from the UIProcess.  It's definitely possible I overlooked something, but everything seems to work.
Comment 23 Sam Weinig 2019-02-11 13:57:22 PST
(In reply to Alex Christensen from comment #22)
> (In reply to Sam Weinig from comment #19)
> > (In reply to Alex Christensen from comment #13)
> > > Comment on attachment 361554 [details]
> > > Patch
> > > 
> > > I put the SPI header definitions in the correct sections, moved the
> > > __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> > > and put the whole "bootstrap" event handler in a std::call_once because it
> > > sets the environment that we won't be able to set with the second xpc
> > > connection to a daemon.
> > 
> > I don't think this is correct for the daemon case. If two UIProcesses with
> > different expectations of the networking daemon connect to it, each with
> > different  initialization criteria, this will not yield the right result.
> > For instance, any OverrideLanguages will not be set. I would think you would
> > either need to remove those UIProcess specific settings completely, or make
> > it so multiple daemons could be spawned, one for each initialization
> > criteria set.
> 
> I don't think this will be a problem right away because there will only be
> one client that uses the SPI to use the daemon, and I think its
> initialization criteria will be the same for each instance.

How do you expect to test this? How will developer builds work? How will Safari Technology Preview work? 

> 
> (In reply to Sam Weinig from comment #20)
> > (In reply to Sam Weinig from comment #19)
> > > (In reply to Alex Christensen from comment #13)
> > > > Comment on attachment 361554 [details]
> > > > Patch
> > > > 
> > > > I put the SPI header definitions in the correct sections, moved the
> > > > __APPLEEVENTSSERVICENAME setting to before the "bootstrap" event handling,
> > > > and put the whole "bootstrap" event handler in a std::call_once because it
> > > > sets the environment that we won't be able to set with the second xpc
> > > > connection to a daemon.
> > > 
> > > I don't think this is correct for the daemon case. If two UIProcesses with
> > > different expectations of the networking daemon connect to it, each with
> > > different  initialization criteria, this will not yield the right result.
> > > For instance, any OverrideLanguages will not be set. I would think you would
> > > either need to remove those UIProcess specific settings completely, or make
> > > it so multiple daemons could be spawned, one for each initialization
> > > criteria set.
> > 
> > When we initially added the bootstrap message using
> > xpc_connection_set_bootstrap/xpc_copy_bootstrap, it was needed because the
> > actions taken needed to happen before xpc_main() was called. What has
> > changed to make that no longer necessary?
> 
> It seems that the setting of the __APPLEEVENTSSERVICENAME environment
> variable is only effective if done before calling xpc_main, but the rest
> seems to work unless I'm missing something.  The part that must be done
> before xpc_main does not depend on any information from the UIProcess.  It's
> definitely possible I overlooked something, but everything seems to work.

One thing I would expect to not be working as expected is localization. From memory, trying to set languages after xpc_main() did not work in the past.
Comment 24 Alex Christensen 2019-02-11 17:50:45 PST
http://trac.webkit.org/r241287
Comment 25 Alex Christensen 2019-02-22 15:33:04 PST
Reopening to attach new patch.
Comment 26 Alex Christensen 2019-02-22 15:33:05 PST
Created attachment 362771 [details]
Patch
Comment 27 Alex Christensen 2019-02-22 16:26:43 PST
Created attachment 362783 [details]
Patch
Comment 28 EWS Watchlist 2019-02-22 16:28:25 PST
Attachment 362783 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/spi/darwin/XPCSPI.h:159:  xpc_connection_set_bootstrap is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/spi/darwin/XPCSPI.h:160:  xpc_copy_bootstrap is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 2 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 29 EWS Watchlist 2019-02-22 17:31:45 PST
Comment on attachment 362783 [details]
Patch

Attachment 362783 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/11254020

New failing tests:
fast/text/international/system-language/han-quotes.html
fast/text/international/system-language/declarative-language.html
Comment 30 EWS Watchlist 2019-02-22 17:31:47 PST
Created attachment 362803 [details]
Archive of layout-test-results from ews106 for mac-highsierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-highsierra-wk2  Platform: Mac OS X 10.13.6
Comment 31 EWS Watchlist 2019-02-22 21:20:11 PST
Comment on attachment 362783 [details]
Patch

Attachment 362783 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/11256733

Number of test failures exceeded the failure limit.
Comment 32 EWS Watchlist 2019-02-22 21:20:13 PST
Created attachment 362815 [details]
Archive of layout-test-results from ews125 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews125  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 33 Alex Christensen 2019-03-01 15:28:36 PST
Created attachment 363381 [details]
Patch
Comment 34 EWS Watchlist 2019-03-01 15:31:19 PST
Attachment 363381 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/spi/darwin/XPCSPI.h:159:  xpc_connection_set_bootstrap is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WTF/wtf/spi/darwin/XPCSPI.h:160:  xpc_copy_bootstrap is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 2 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 35 Alex Christensen 2019-03-01 18:30:38 PST
http://trac.webkit.org/r242303