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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>14331</bug_id>
          
          <creation_ts>2011-09-29 10:00:19 +0000</creation_ts>
          <short_desc>EventSource can end up in the wrong state due to race conditions (see comment 12 paragraph 2)</short_desc>
          <delta_ts>2011-10-27 20:31:38 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Server-Sent Events (editor: Ian Hickson)</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#top</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>annevk</cc>
    
    <cc>art.barstow</cc>
    
    <cc>ian</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
    
    <cc>vic99999</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>57500</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-09-29 10:00:19 +0000</bug_when>
    <thetext>Specification: http://dev.w3.org/html5/eventsource/
Multipage: http://www.whatwg.org/C#top
Complete: http://www.whatwg.org/c#top

Comment:
Hello!

Why tasks that are queued by EventSource doesnot removed from task queues with
&quot;close&quot; method?

Thanks!


Posted from: 217.19.114.226
User agent: Opera/9.80 (Windows NT 6.0; U; Edition Next; ru) Presto/2.9.205 Version/12.00</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57640</commentid>
    <comment_count>1</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-02 16:39:36 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Did Not Understand Request
Change Description: no spec change
Rationale: Why would they be?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57656</commentid>
    <comment_count>2</comment_count>
    <who name="">vic99999</who>
    <bug_when>2011-10-02 17:14:16 +0000</bug_when>
    <thetext>&quot;message&quot; and &quot;open&quot; events will fire even after calling &quot;eventSource.close()&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57657</commentid>
    <comment_count>3</comment_count>
    <who name="">vic99999</who>
    <bug_when>2011-10-02 17:16:31 +0000</bug_when>
    <thetext>XMLHttpRequest#abort(), opposite, clears task in tasks queue to fire &quot;readystatechange&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57706</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-03 16:08:48 +0000</bug_when>
    <thetext>I guess we can clear them, but that just means we&apos;re discarding  events that were received before the close() method was called (even though they&apos;re being fired after).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57712</commentid>
    <comment_count>5</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2011-10-03 17:02:20 +0000</bug_when>
    <thetext>Indeed, I think firing messages after .close() is called is much more likely to cause bugs than provide value. I don&apos;t think most authors think about these things in terms of several threads sending asynchronous messages to each other, and more in the terms of a single thread where everything is happening.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57724</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-03 22:24:09 +0000</bug_when>
    <thetext>Fair enough. Will do.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57758</commentid>
    <comment_count>7</comment_count>
    <who name="">vic99999</who>
    <bug_when>2011-10-04 06:55:43 +0000</bug_when>
    <thetext>anyway,
calling stop() while event dispatching will not prevent other event handlers calling
but i think, that it&apos;s better to make &quot;close()&quot; behavior to be more similar to XMLHttpRequest#abort() and WebSockets#close()</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58260</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-14 22:34:44 +0000</bug_when>
    <thetext>Note that WebSocket.close() doesn&apos;t do this either. Changing that would contradict the protocol spec: WebSockets is explicitly designed to allow you to close the connection before you&apos;ve finished receiving everything you&apos;re going to get; there&apos;s a clearly defined end handshake.

I&apos;ve fixed this for EventSource though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58261</commentid>
    <comment_count>9</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-10-14 22:35:02 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r6688.
Check-in comment: Make EventSource.close() cause the events to stop firing even if they&apos;re already queued.
http://html5.org/tools/web-apps-tracker?from=6687&amp;to=6688</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58267</commentid>
    <comment_count>10</comment_count>
    <who name="">vic99999</who>
    <bug_when>2011-10-15 04:40:51 +0000</bug_when>
    <thetext>what about &quot;open&quot; and &quot;error&quot; events?
It seems, they should also be dropped...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58268</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-15 04:47:56 +0000</bug_when>
    <thetext>Seems easier to just empty the &quot;remote event task source&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58369</commentid>
    <comment_count>12</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-18 20:06:37 +0000</bug_when>
    <thetext>Emptying the task source is a bit dodgy because you&apos;d have to make sure to only empty the tasks that were fired for this specific EventSource object. You also have to make sure that no new tasks get queued.

Agreed that &apos;open&apos; events shouldn&apos;t fire, though. In particular, as specced, if you call close() between the connection being open and the &apos;open&apos; event firing, the object will end up in the wrong state. A similar problem exists for &apos;error&apos;, but it&apos;s actually worse; if the connection closes just before you call close(), per spec, the connection will actually be reopened! I&apos;ll fix that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58410</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-19 03:27:15 +0000</bug_when>
    <thetext>That is what XMLHttpRequest does and HTML media elements do. E.g. from HTML:

&quot;If there are any tasks from the media element&apos;s media element event task source in one of the task queues, then remove those tasks.&quot;

I used that language for XMLHttpRequest.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58831</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-25 02:55:26 +0000</bug_when>
    <thetext>It works for media elements because each one has its own task source.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58847</commentid>
    <comment_count>15</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-25 03:35:33 +0000</bug_when>
    <thetext>Oh I see, it seems it would be simple to do the same for EventSource. I should update XMLHttpRequest to say the task source is per object.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59095</commentid>
    <comment_count>16</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-10-27 20:29:58 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with reporter&apos;s comments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>59096</commentid>
    <comment_count>17</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-10-27 20:31:38 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r6772.
Check-in comment: Make sure once you call closed() that EventSource objects stay down.
http://html5.org/tools/web-apps-tracker?from=6771&amp;to=6772</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>