<?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>147036</bug_id>
          
          <creation_ts>2015-07-17 01:31:53 -0700</creation_ts>
          <short_desc>[GTK] WebProcessMain::platformFinalize() is not called when web process finished with exit(0)</short_desc>
          <delta_ts>2017-08-07 05:43:25 -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>WebKit2</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=168126</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Gtk</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Garcia Campos">cgarcia</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>andersca</cc>
    
    <cc>darin</cc>
    
    <cc>mcatanzaro</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1110103</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-17 01:31:53 -0700</bug_when>
    <thetext>This happens very often when the web process finishes from Connection::didFailToSendSyncMessage(). At least for the GTK+ port, we could stop the main loop instead of calling exit, and that way, the platformFinalize() method will be called.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110104</commentid>
    <comment_count>1</comment_count>
      <attachid>256961</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-17 01:37:07 -0700</bug_when>
    <thetext>Created attachment 256961
Patch

If stopping the run loop works also for other ports we could get rid of the platform ifdef.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110644</commentid>
    <comment_count>2</comment_count>
      <attachid>256961</attachid>
    <who name="Martin Robinson">mrobinson</who>
    <bug_when>2015-07-20 09:58:13 -0700</bug_when>
    <thetext>Comment on attachment 256961
Patch

Looks good to me, but I guess we need a review from an Apple person.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110847</commentid>
    <comment_count>3</comment_count>
      <attachid>256961</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-07-20 17:38:10 -0700</bug_when>
    <thetext>Comment on attachment 256961
Patch

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

&gt; Source/WebKit2/Platform/IPC/Connection.cpp:863
&gt; +#if PLATFORM(GTK)
&gt; +    RunLoop::main().stop();
&gt; +#else
&gt;      exit(0);
&gt; +#endif

Anders, do you think we should just do the RunLoop::stop thing on all platforms? I need more context. What’s the critical code in platformFinalize that always needs to be called?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110854</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-07-20 18:00:20 -0700</bug_when>
    <thetext>For GTK it is the code Carlos is adding to save the clipboard contents in the clipboard manager, so that you can paste data that you copied from a web process after closing the web process.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1110894</commentid>
    <comment_count>5</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-20 22:24:55 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; For GTK it is the code Carlos is adding to save the clipboard contents in
&gt; the clipboard manager, so that you can paste data that you copied from a web
&gt; process after closing the web process.

And also the soup cache dump when using the shared secondary process model, which is very important to keep the disk cache resources in sync with the index.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1111959</commentid>
    <comment_count>6</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-24 03:03:32 -0700</bug_when>
    <thetext>ping? This patch doesn&apos;t actually change any cross-platform behaviour, so maybe we can unblock this by landing the patch and decide whether to remove the platform #ifdef later if the solution is valid for other ports.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112309</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-07-26 11:19:08 -0700</bug_when>
    <thetext>I agree with Carlos, especially since this is needed to fix a major data loss bug. Martin/Darin, can you please grant review?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112355</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-07-26 21:51:38 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; For GTK it is the code Carlos is adding to save the clipboard contents in
&gt; the clipboard manager, so that you can paste data that you copied from a web
&gt; process after closing the web process.

It would be much better to do that earlier, perhaps based on some coalescing timer. You don’t want to lose the clipboard if the web process crashes. Generally it’s not a good pattern to have any code that runs only on exit. One of the main benefits of having a web process is better behavior if a crash occurs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112377</commentid>
    <comment_count>9</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-27 00:37:49 -0700</bug_when>
    <thetext>(In reply to comment #8)
&gt; (In reply to comment #4)
&gt; &gt; For GTK it is the code Carlos is adding to save the clipboard contents in
&gt; &gt; the clipboard manager, so that you can paste data that you copied from a web
&gt; &gt; process after closing the web process.
&gt; 
&gt; It would be much better to do that earlier, perhaps based on some coalescing
&gt; timer. You don’t want to lose the clipboard if the web process crashes.
&gt; Generally it’s not a good pattern to have any code that runs only on exit.
&gt; One of the main benefits of having a web process is better behavior if a
&gt; crash occurs.

gtk_clipboard_store() is expected to be called only when the application is about to quit, and that&apos;s what all GTK+ applications do, because GTK calls it after the main loop quits. We could use a compiler destructor to do all the cleanup though, but I still thing exit(0) is not the best way to finish the web process when we can just quit the main loop, and finish properly from main.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112410</commentid>
    <comment_count>10</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-07-27 07:43:21 -0700</bug_when>
    <thetext>(In reply to comment #9) 
&gt; gtk_clipboard_store() is expected to be called only when the application is
&gt; about to quit, and that&apos;s what all GTK+ applications do, because GTK calls
&gt; it after the main loop quits.

Well... that is certainly the common usage, but I think it&apos;s fine to call gtk_clipboard_store() whenever we receive data. Otherwise, it&apos;s hard to think of why else the API exists, if not to be used. The benefit would be as Darin mentions. The cost would be performance in the case of huge clipboard selections, but that&apos;s not a super practical concern, and clipboard managers can reject selections that are too big. So I think either approach is fine.

(In reply to comment #9)
&gt; I still thing exit(0) is not the best way to finish
&gt; the web process when we can just quit the main loop, and finish properly
&gt; from main.

Agreed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112563</commentid>
    <comment_count>11</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-07-27 16:04:48 -0700</bug_when>
    <thetext>(In reply to comment #9)
&gt; I still thing exit(0) is not the best way to finish
&gt; the web process when we can just quit the main loop, and finish properly
&gt; from main.

I think we should continue to use exit(0); seems it would be faster. But I understand that you might not agree.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112693</commentid>
    <comment_count>12</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-28 01:53:26 -0700</bug_when>
    <thetext>(In reply to comment #11)
&gt; (In reply to comment #9)
&gt; &gt; I still thing exit(0) is not the best way to finish
&gt; &gt; the web process when we can just quit the main loop, and finish properly
&gt; &gt; from main.
&gt; 
&gt; I think we should continue to use exit(0); seems it would be faster. But I
&gt; understand that you might not agree.

So, would you be opposed to leave the exit(0) for other ports and quit the main loop for GTK+ only? Otherwise I will just remove the platformFinalize and use a compiler destructor instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112791</commentid>
    <comment_count>13</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-07-28 11:55:28 -0700</bug_when>
    <thetext>(In reply to comment #12)
&gt; So, would you be opposed to leave the exit(0) for other ports and quit the
&gt; main loop for GTK+ only?

Yes, I am opposed to it. Not necessarily strongly opposed, but I don’t want to do this in WebKit.

&gt; Otherwise I will just remove the platformFinalize
&gt; and use a compiler destructor instead.

In case it’s not clear, I’m opposed to that too.

WebKit should not have code that relies on running when the process exits. Not good architecture.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1112929</commentid>
    <comment_count>14</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-07-28 16:41:51 -0700</bug_when>
    <thetext>(In reply to comment #13) 
&gt; WebKit should not have code that relies on running when the process exits.
&gt; Not good architecture.

FWIW we already have such code, but I don&apos;t know where or why, and it&apos;s causing crashes: bug #145347</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1113073</commentid>
    <comment_count>15</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2015-07-29 05:47:15 -0700</bug_when>
    <thetext>(In reply to comment #10)
&gt; (In reply to comment #9) 
&gt; &gt; gtk_clipboard_store() is expected to be called only when the application is
&gt; &gt; about to quit, and that&apos;s what all GTK+ applications do, because GTK calls
&gt; &gt; it after the main loop quits.
&gt; 
&gt; Well... that is certainly the common usage, but I think it&apos;s fine to call
&gt; gtk_clipboard_store() whenever we receive data. Otherwise, it&apos;s hard to
&gt; think of why else the API exists, if not to be used.

The fact that the API exists doesn&apos;t mean it&apos;s convenient to be used at any moment. gtk_clipboard_store uses a nested main loop with a timeout of 10 milliseconds. The nested main loop uses the default main context, so any other sources sent to the default main context (like an IPC message handler) would be handled by the nested main loop. That can cause problems, I had a lot of issues with the nested main loop used by gtk_enumerate_printers, because it handled other sources, for example. So, the safest way to use this API, which is how everybody uses it (included firefox for example), is to call it when the application finishes, right after the main loop quits.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>256961</attachid>
            <date>2015-07-17 01:37:07 -0700</date>
            <delta_ts>2015-07-29 23:10:25 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>wk2-platform-finalize.diff</filename>
            <type>text/plain</type>
            <size>1495</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJLaXQyL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJLaXQyL0No
YW5nZUxvZwppbmRleCAwZWY3NmI5Li4wODM2YTg4IDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViS2l0
Mi9DaGFuZ2VMb2cKKysrIGIvU291cmNlL1dlYktpdDIvQ2hhbmdlTG9nCkBAIC0xLDUgKzEsMjAg
QEAKIDIwMTUtMDctMTcgIENhcmxvcyBHYXJjaWEgQ2FtcG9zICA8Y2dhcmNpYUBpZ2FsaWEuY29t
PgogCisgICAgICAgIFtHVEtdIFdlYlByb2Nlc3NNYWluOjpwbGF0Zm9ybUZpbmFsaXplKCkgaXMg
bm90IGNhbGxlZCB3aGVuIHdlYiBwcm9jZXNzIGZpbmlzaGVkIHdpdGggZXhpdCgwKQorICAgICAg
ICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTQ3MDM2CisKKyAgICAg
ICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgVGhpcyBoYXBwZW5zIHZl
cnkgb2Z0ZW4gd2hlbiB0aGUgd2ViIHByb2Nlc3MgZmluaXNoZXMgZnJvbQorICAgICAgICBDb25u
ZWN0aW9uOjpkaWRGYWlsVG9TZW5kU3luY01lc3NhZ2UoKS4gQXQgbGVhc3QgZm9yIHRoZSBHVEsr
CisgICAgICAgIHBvcnQsIHdlIGNvdWxkIHN0b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