This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14331 - EventSource can end up in the wrong state due to race conditions (see comment 12 paragraph 2)
Summary: EventSource can end up in the wrong state due to race conditions (see comment...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Server-Sent Events (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: public-webapps-bugzilla
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-29 10:00 UTC by contributor
Modified: 2011-10-27 20:31 UTC (History)
7 users (show)

See Also:


Attachments

Description contributor 2011-09-29 10:00:19 UTC
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
"close" 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
Comment 1 Ian 'Hixie' Hickson 2011-10-02 16:39:36 UTC
EDITOR'S RESPONSE: This is an Editor'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?
Comment 2 vic99999 2011-10-02 17:14:16 UTC
"message" and "open" events will fire even after calling "eventSource.close()"
Comment 3 vic99999 2011-10-02 17:16:31 UTC
XMLHttpRequest#abort(), opposite, clears task in tasks queue to fire "readystatechange"
Comment 4 Ian 'Hixie' Hickson 2011-10-03 16:08:48 UTC
I guess we can clear them, but that just means we're discarding  events that were received before the close() method was called (even though they're being fired after).
Comment 5 Jonas Sicking (Not reading bugmail) 2011-10-03 17:02:20 UTC
Indeed, I think firing messages after .close() is called is much more likely to cause bugs than provide value. I don'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.
Comment 6 Ian 'Hixie' Hickson 2011-10-03 22:24:09 UTC
Fair enough. Will do.
Comment 7 vic99999 2011-10-04 06:55:43 UTC
anyway,
calling stop() while event dispatching will not prevent other event handlers calling
but i think, that it's better to make "close()" behavior to be more similar to XMLHttpRequest#abort() and WebSockets#close()
Comment 8 Ian 'Hixie' Hickson 2011-10-14 22:34:44 UTC
Note that WebSocket.close() doesn't do this either. Changing that would contradict the protocol spec: WebSockets is explicitly designed to allow you to close the connection before you've finished receiving everything you're going to get; there's a clearly defined end handshake.

I've fixed this for EventSource though.
Comment 9 contributor 2011-10-14 22:35:02 UTC
Checked in as WHATWG revision r6688.
Check-in comment: Make EventSource.close() cause the events to stop firing even if they're already queued.
http://html5.org/tools/web-apps-tracker?from=6687&to=6688
Comment 10 vic99999 2011-10-15 04:40:51 UTC
what about "open" and "error" events?
It seems, they should also be dropped...
Comment 11 Anne 2011-10-15 04:47:56 UTC
Seems easier to just empty the "remote event task source".
Comment 12 Ian 'Hixie' Hickson 2011-10-18 20:06:37 UTC
Emptying the task source is a bit dodgy because you'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 'open' events shouldn't fire, though. In particular, as specced, if you call close() between the connection being open and the 'open' event firing, the object will end up in the wrong state. A similar problem exists for 'error', but it's actually worse; if the connection closes just before you call close(), per spec, the connection will actually be reopened! I'll fix that.
Comment 13 Anne 2011-10-19 03:27:15 UTC
That is what XMLHttpRequest does and HTML media elements do. E.g. from HTML:

"If there are any tasks from the media element's media element event task source in one of the task queues, then remove those tasks."

I used that language for XMLHttpRequest.
Comment 14 Ian 'Hixie' Hickson 2011-10-25 02:55:26 UTC
It works for media elements because each one has its own task source.
Comment 15 Anne 2011-10-25 03:35:33 UTC
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.
Comment 16 Ian 'Hixie' Hickson 2011-10-27 20:29:58 UTC
EDITOR'S RESPONSE: This is an Editor'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's comments.
Comment 17 contributor 2011-10-27 20:31:38 UTC
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&to=6772