<?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>278313</bug_id>
          
          <creation_ts>2024-08-19 07:21:17 -0700</creation_ts>
          <short_desc>WebSocket close event is not fired when close() is called.</short_desc>
          <delta_ts>2024-08-29 13:48:37 -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>WebKit Misc.</component>
          <version>Safari 17</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 17</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=274003</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="Andrew Hodel">andrewhodel</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>ajuma</cc>
    
    <cc>ap</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2053705</commentid>
    <comment_count>0</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-19 07:21:17 -0700</bug_when>
    <thetext>Steps to reproduce the problem

1. Connect a new WebSocket();
2. Disgrace the network connection to ensure packets are delayed and dropped causing TCP resends (RST flagged packets). This is possible with iptables, pf, or by using your computer with a radio link and a poor radio signal. (WiFi, LTE, etc).
3. Call the close() function on the WebSocket object you created in step 1. As the WebSocket close() function was called within the code of the WebSocket client, the close event should fire immediately. It does not.

Problem Description

As the WebSocket close() function was called within the code of the WebSocket client, the close event should fire immediately. It does not.



If believe that a WebSocket close (opcode 8) message must be delivered for the close event to happen without a timeout triggering it:

You can kill the server and see that the close event on the client fires immediately without an opcode 8 message being sent. Either that or this must be a bug.
It is most reasonable that the WebSocket close() function makes the close event fire immediately because:

It makes reconnecting faster when you are sure there is a disconnection based on a keep-alive (ping, etc) mechanism.
Keep in mind that this only happens when there is a poor network connection.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053725</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2024-08-19 08:44:26 -0700</bug_when>
    <thetext>We are tracking multiple issues that result in this behavior. There were two fixes in iOS 17.6.1. One was in WebKit, and one in an underlying system framework. But the issue doesn&apos;t appear to be fully resolved, so there is more to fix.

Which OS version are you observing this with?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053735</commentid>
    <comment_count>2</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-19 09:13:24 -0700</bug_when>
    <thetext>@Alexey Proskuryakov please link the issues using a hyperlink.

You have described the same routine as implementing a work-around to this problem/issue in JavaScript and it must not be the solution or fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053806</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2024-08-19 12:09:18 -0700</bug_when>
    <thetext>I add the WebKit issue to See Also; others are Apple internal. My question still stands, which OS version are you observing this with?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053817</commentid>
    <comment_count>4</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-19 12:39:11 -0700</bug_when>
    <thetext>@ Alexey Proskuryakov

That&apos;s already specified in the bug&apos;s fields.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053824</commentid>
    <comment_count>5</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2024-08-19 12:49:18 -0700</bug_when>
    <thetext>Please try to refrain from unwarranted snark.

The bug field says &quot;iOS 17&quot;, and I&apos;m asking you about the precise version, as some fixes went into iOS 17.6.1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053829</commentid>
    <comment_count>6</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-19 13:02:22 -0700</bug_when>
    <thetext>@Alexey Proskuryakov

At this time, with this product the fact is that there is no reason to not have the latest updates by the Operating System if you are on Earth.  I think that is why the fields were not constructed correctly, alongside there not being an standard protocol or URL structure to import the data from the browser manufacturers.

I understand the problem of alignment of thought, regarding that this may not be true as latency of communication increases and believe that the field should have more specific version information.  I don&apos;t think your comment adequately explained that.

I am using the latest version of iPadOS 17 and that includes the latest version of Safari 17.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053842</commentid>
    <comment_count>7</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-19 13:22:25 -0700</bug_when>
    <thetext>@Alexey Proskuryakov

17.6.1

I installed it days ago.

Again, this is simply a re-iteration of the two places to check and time problem and that is not how the problem in the WebSocket implementation is resolved.  That is how a work around of fixing in JavaScript again and again works.

It&apos;s not needed to do this, approaches of visualization instead of questioning create a result based instead of control based orient.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053891</commentid>
    <comment_count>8</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2024-08-19 14:43:25 -0700</bug_when>
    <thetext>Thank you for the report. Talked to the responsible engineers, we believe that this is the known issue that we track internally, rdar://128224509 (link for Apple employees).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2055158</commentid>
    <comment_count>9</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-24 15:16:59 -0700</bug_when>
    <thetext>Guten Tag!

Your SMTP server didn&apos;t accept an email from Gmail when I replied the day you made your final comment, in year 2024!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2055789</commentid>
    <comment_count>10</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-27 18:00:41 -0700</bug_when>
    <thetext>You can cause other browsers to do this by dropping the traffic at the server with iptables.

However, with most browsers other than the iPad removing the drop rule invokes the close event as a packet with a FIN flag is sent from the server if the server already closed the tcp socket by it&apos;s timeout and the browser&apos;s machine tries to reuse it.

The iPad sits and waits until it has a timeout, and the WebSocket constructor does not allow you to set a timeout.

This is important information.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2055790</commentid>
    <comment_count>11</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-08-27 18:01:15 -0700</bug_when>
    <thetext>&lt;rdar://problem/134821877&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056028</commentid>
    <comment_count>12</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2024-08-28 12:57:40 -0700</bug_when>
    <thetext>This is being tracked as an issue in a system framework outside WebKit, so there will be no further communication here. You can reach out to Apple if appropriate.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056053</commentid>
    <comment_count>13</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-28 13:47:42 -0700</bug_when>
    <thetext>That&apos;s not true, I am reaching out to Apple.

Apple owns the domain webkit.org

https://who.is/whois/webkit.org</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056340</commentid>
    <comment_count>14</comment_count>
    <who name="Andrew Hodel">andrewhodel</who>
    <bug_when>2024-08-29 12:25:52 -0700</bug_when>
    <thetext>Also, the Safari browser on iPad chooses to refresh the document if you disconnect and reconnect the WiFi network using the iPadOS menu to force the socket to close and the WebSocket `close` event to fire.

It has done this after 3 disconnect and connect iterations.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2056364</commentid>
    <comment_count>15</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2024-08-29 13:48:37 -0700</bug_when>
    <thetext>That would be a different issue, and I cannot reproduce it using iOS 18 beta on https://ws-playground.netlify.app. Please file a new bug report with configuration details and steps to reproduce.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>