<?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>168126</bug_id>
          
          <creation_ts>2017-02-10 10:23:14 -0800</creation_ts>
          <short_desc>[GTK][WPE] WebProcess should run cleanup on quit to release resources</short_desc>
          <delta_ts>2018-04-09 13:08:34 -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>WebKitGTK</component>
          <version>Other</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=166029</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=146657</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=147036</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=183348</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Olivier Blin">olivier.blin</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annulen</cc>
    
    <cc>beidson</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>cgarcia</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>zan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1275367</commentid>
    <comment_count>0</comment_count>
    <who name="Olivier Blin">olivier.blin</who>
    <bug_when>2017-02-10 10:23:14 -0800</bug_when>
    <thetext>When the UI Process is closed, the WebProcess does not always run a proper cleanup, and may not properly close system resources.
For example, the MediaPlayerPrivateGStreamerBase destructor may not be called.

This can be especially annoying on embedded devices, where video drivers do not always run a device cleanup when the process using it is terminated.

This has been seen initially on WebKitForWayland with GStreamer, and WebKitGTK has the same behavior.

When exiting MiniBrowser by closing the graphical window, WebPage::close() is called on the WebProcess, and it leads most of the time to a successful call of ~MediaPlayerPrivateGStreamerBase().
When exiting MiniBrowser from command line with Ctrl-C, SIGINT is sent to all process in the process group, and WebProcess quits without properly destroying its objects.
When exiting MiniBrowser with killall (SIGTERM), the WebProcess also quits without destroying its objects.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1275394</commentid>
    <comment_count>1</comment_count>
    <who name="Olivier Blin">olivier.blin</who>
    <bug_when>2017-02-10 10:41:03 -0800</bug_when>
    <thetext>We could catch SIGINT in the WebProcess, as discussed on IRC with Zan and Konstantin a few months ago, but there is no ideal method to call to run the WebProcess exit.

If we add a SIGINT handler and do nothing more, the IPC connection close will eventually be detected.
But in release mode, WebProcess::didClose() does not run the WebPage cleanup.

After enabling the code that runs WebPage::close() in WebProcess::didClose(), the WebProcess will exit even earlier because of extra IPC failure checks:

#0  __GI_exit (status=0) at exit.c:104
#1  0x00007f914bceda79 in IPC::Connection::sendSyncMessage(unsigned long, std::unique_ptr&lt;IPC::Encoder, std::default_delete&lt;IPC::Encoder&gt; &gt;, WTF::Seconds, WTF::OptionSet&lt;IPC::SendSyncOption&gt;) () from libwebkit2gtk-4.0.so.37
#2  0x00007f914bdf35fb in bool IPC::Connection::sendSync&lt;Messages::WebProcessProxy::ShouldTerminate&gt;(Messages::WebProcessProxy::ShouldTerminate&amp;&amp;, Messages::WebProcessProxy::ShouldTerminate::Reply&amp;&amp;, unsigned long, WTF::Seconds, WTF::OptionSet&lt;IPC::SendSyncOption&gt;) () from libwebkit2gtk-4.0.so.37
#3  0x00007f914bdedec8 in WebKit::WebProcess::shouldTerminate() () from libwebkit2gtk-4.0.so.37
#4  0x00007f914bcfc4e3 in WebKit::ChildProcess::enableTermination() () from libwebkit2gtk-4.0.so.37
#5  0x00007f914be76da0 in WebKit::WebPage::close() () from libwebkit2gtk-4.0.so.37
#6  0x00007f914bdee178 in WebKit::WebProcess::didClose(IPC::Connection&amp;) () from libwebkit2gtk-4.0.so.37

And if we call WebProcess::singleton().parentProcessConnection()-&gt;setShouldExitOnSyncMessageSendFailure(false) in the SIGINT handler, this leads to different crashes later on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1275409</commentid>
    <comment_count>2</comment_count>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-02-10 10:55:55 -0800</bug_when>
    <thetext>It might be a better idea to add new IPC message that instructs WebProcess to shutdown. FWIW, there were requests to make graceful restart of WebProcess possible, and having this message would be useful for both cases</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1275416</commentid>
    <comment_count>3</comment_count>
    <who name="Olivier Blin">olivier.blin</who>
    <bug_when>2017-02-10 11:02:02 -0800</bug_when>
    <thetext>Looks like a good idea.
But we still need to find a way to close the WebPage objects without crashing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1275734</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-02-10 20:23:42 -0800</bug_when>
    <thetext>Just to be clear, this is definitely a bug in the video drivers, right? Not releasing system resources when the process quits is pretty wild....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1275762</commentid>
    <comment_count>5</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-02-10 23:13:16 -0800</bug_when>
    <thetext>This is not specific to the web process, though. We have similar issues with the network process because the soup session is not properly finished. See bug #166029.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1275870</commentid>
    <comment_count>6</comment_count>
    <who name="Olivier Blin">olivier.blin</who>
    <bug_when>2017-02-11 15:38:25 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; Just to be clear, this is definitely a bug in the video drivers, right? Not
&gt; releasing system resources when the process quits is pretty wild....

Yes, it is a bug in the video drivers.
Unfortunately, this is not uncommon in proprietary drivers for embedded devices.

It would be good to have a graceful WebProcess exit.
Is there any reason not to do so?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1276216</commentid>
    <comment_count>7</comment_count>
    <who name="Zan Dobersek">zan</who>
    <bug_when>2017-02-13 09:41:56 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; When exiting MiniBrowser by closing the graphical window, WebPage::close()
&gt; is called on the WebProcess, and it leads most of the time to a successful
&gt; call of ~MediaPlayerPrivateGStreamerBase().

This should always be the preferred path. To what degree things can be uninitialized is to be seen I guess. We&apos;ve had issues with graphics drivers and atexit handlers before.

&gt; When exiting MiniBrowser from command line with Ctrl-C, SIGINT is sent to
&gt; all process in the process group, and WebProcess quits without properly
&gt; destroying its objects.
&gt; When exiting MiniBrowser with killall (SIGTERM), the WebProcess also quits
&gt; without destroying its objects.

This can get tricky. Ideally WebProcess would only be closed when the UIProcess signals it to do so. Sending SIGINT or SIGTERM directly at a WebProcess or NetworkProcess should also kill it.

But Ctrl-C is a bit special since it&apos;s super useful for development purposes, yet can&apos;t be worked around easily since it sends out SIGINT to all the processes in the process group, and AFAIU if we don&apos;t handle SIGINT in the WebProcess, SIGINT will kill that WebProcess before the UIProcess can shut it down when it handles its own SIGINT.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1276231</commentid>
    <comment_count>8</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-02-13 10:29:12 -0800</bug_when>
    <thetext>As a rule, I&apos;m opposed to adding workarounds to WebKit for bugs in crap proprietary software. But in this case it seems like the WebKit behavior should be improved regardless. Our secondary processes should probably behave similarly to how I decided to handle this in Epiphany:

 * First time a shutdown signal (SIGINT or SIGTERM) is received, attempt to quit normally, the same way we would if attempting to close the graphical window. It may fail.
 * Second time a shutdown signal is received, quit immediately. Useful in case something goes wrong in step one.

Note: I think it&apos;s important for GLib ports to catch the shutdown signals using g_unix_signal_add() rather than the low-level POSIX APIs, in order to avoid the massive amount of problems and races with UNIX signal handling and async signal safety. In Epiphany, I implemented the above by connecting the signal source once and always disconnecting it when received, so that receiving the signal subsequently would trigger the default killer handler. Note that it doesn&apos;t always work because sometimes the signal source handler gets stuck running forever; I never figured out why.

Note: In any case, *always* end with re-raising the caught signal, so that the process exit status indicates the signal that was received.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1335260</commentid>
    <comment_count>9</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-08-04 08:36:33 -0700</bug_when>
    <thetext>This is not specific to GTK+ port</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1335946</commentid>
    <comment_count>10</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2017-08-07 07:28:10 -0700</bug_when>
    <thetext>(In reply to Olivier Blin from comment #6)
&gt; (In reply to comment #4)
&gt; &gt; Just to be clear, this is definitely a bug in the video drivers, right? Not
&gt; &gt; releasing system resources when the process quits is pretty wild....
&gt; 
&gt; Yes, it is a bug in the video drivers.
&gt; Unfortunately, this is not uncommon in proprietary drivers for embedded
&gt; devices.
&gt; 
&gt; It would be good to have a graceful WebProcess exit.
&gt; Is there any reason not to do so?

Yes. It will slow down things like quitting the browser with lots of tabs open. And on platforms without these issues, it will slow them unnecessarily.

If this is truly needed for GTK/WPE/etc, it will need to be specific to those platforms.

We don&apos;t want to slow down WebView destruction on Mac/iOS</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1335954</commentid>
    <comment_count>11</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-08-07 08:22:56 -0700</bug_when>
    <thetext>(In reply to Brady Eidson from comment #10)
&gt; If this is truly needed for GTK/WPE/etc, it will need to be specific to
&gt; those platforms.

Well it depends. On Linux it is considered nice, but optional, to release system resources before process termination. The OS is responsible for handling that if the process does not. The original reported problem here seems to be a bug with some graphics driver not doing that. We definitely do not need to support broken drivers, at least not upstream. The driver needs to be fixed.

Now, we really do need to finalize the SoupSession, but we already do that now (bug #166029) and that doesn&apos;t affect macOS at all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1337875</commentid>
    <comment_count>12</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-08-11 06:36:59 -0700</bug_when>
    <thetext>(In reply to Brady Eidson from comment #10)
&gt; (In reply to Olivier Blin from comment #6)
&gt; &gt; (In reply to comment #4)
&gt; &gt; &gt; Just to be clear, this is definitely a bug in the video drivers, right? Not
&gt; &gt; &gt; releasing system resources when the process quits is pretty wild....
&gt; &gt; 
&gt; &gt; Yes, it is a bug in the video drivers.
&gt; &gt; Unfortunately, this is not uncommon in proprietary drivers for embedded
&gt; &gt; devices.
&gt; &gt; 
&gt; &gt; It would be good to have a graceful WebProcess exit.
&gt; &gt; Is there any reason not to do so?
&gt; 
&gt; Yes. It will slow down things like quitting the browser with lots of tabs
&gt; open. And on platforms without these issues, it will slow them unnecessarily.
&gt; 
&gt; If this is truly needed for GTK/WPE/etc, it will need to be specific to
&gt; those platforms.
&gt; 
&gt; We don&apos;t want to slow down WebView destruction on Mac/iOS

I think we could start by not calling setShouldExitOnSyncMessageSendFailure() for GTK and WPE ports, just to try.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355236</commentid>
    <comment_count>13</comment_count>
      <attachid>322376</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-10-02 08:06:35 -0700</bug_when>
    <thetext>Created attachment 322376
Patch

Let&apos;s try this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355238</commentid>
    <comment_count>14</comment_count>
    <who name="Olivier Blin">olivier.blin</who>
    <bug_when>2017-10-02 08:42:01 -0700</bug_when>
    <thetext>(In reply to Carlos Garcia Campos from comment #13)
&gt; Created attachment 322376 [details]
&gt; Patch
&gt; 
&gt; Let&apos;s try this.

I think I tried this, and it did not end well.
I don&apos;t remember where it was crashing though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355283</commentid>
    <comment_count>15</comment_count>
      <attachid>322376</attachid>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-10-02 10:22:49 -0700</bug_when>
    <thetext>Comment on attachment 322376
Patch

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

I&apos;m fully expecting many horrible regressions, but let&apos;s give it a try and see.

&gt; Source/WebKit/WebProcess/WebProcess.cpp:219
&gt; +#if !PLATFORM(GTK) &amp;&amp; !PLAFORM(WPE)

PLAFORM -&gt; PLATFORM</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355728</commentid>
    <comment_count>16</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-10-03 01:12:29 -0700</bug_when>
    <thetext>Committed r222772: &lt;http://trac.webkit.org/changeset/222772&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355751</commentid>
    <comment_count>17</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-10-03 02:28:01 -0700</bug_when>
    <thetext>BTW, it should go without saying, but since we know to expect regressions, *please* do not backport this to 2.18.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>322376</attachid>
            <date>2017-10-02 08:06:35 -0700</date>
            <delta_ts>2017-10-02 10:22:49 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>wk2-exit-on-sync-failure.diff</filename>
            <type>text/plain</type>
            <size>1274</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nIGIvU291cmNlL1dlYktpdC9DaGFu
Z2VMb2cKaW5kZXggZWE2ZTQyZjM1ZmYuLjVmNzZiMDI4NWNlIDEwMDY0NAotLS0gYS9Tb3VyY2Uv
V2ViS2l0L0NoYW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WJQcm9jZXNzLmNwcApAQCAtMjE2LDcgKzIxNiw5IEBAIHZvaWQgV2ViUHJvY2Vz
czo6aW5pdGlhbGl6ZUNvbm5lY3Rpb24oSVBDOjpDb25uZWN0aW9uKiBjb25uZWN0aW9uKQogewog
ICAgIENoaWxkUHJvY2Vzczo6aW5pdGlhbGl6ZUNvbm5lY3Rpb24oY29ubmVjdGlvbik7CiAKKyNp
ZiAhUExBVEZPUk0oR1RLKSAmJiAhUExBRk9STShXUEUpCiAgICAgY29ubmVjdGlvbi0+c2V0U2hv
dWxkRXhpdE9uU3luY01lc3NhZ2VTZW5kRmFpbHVyZSh0cnVlKTsKKyNlbmRpZgogCiAjaWYgSEFW
RShRT1NfQ0xBU1NFUykKICAgICBjb25uZWN0aW9uLT5zZXRTaG91bGRCb29zdE1haW5UaHJlYWRP
blN5bmNNZXNzYWdlKHRydWUpOwo=
</data>
<flag name="review"
          id="342249"
          type_id="1"
          status="+"
          setter="mcatanzaro"
    />
          </attachment>
      

    </bug>

</bugzilla>