[whatwg] [EventSource] Garbage collection rules

Stewart Brodie stewart.brodie at antplc.com
Fri Jul 10 06:37:14 PDT 2009


I've been reviewing the new EventSource draft.  I'm very pleased to see it
converted into a separate object, rather than being tacked onto everything
that implements EventTarget.  This is a huge improvement.  However, there
are some issues that I think need to be addressed, specifically in the area
of lifetime management.

The GC rules in section 9 seem overly permissive - if there is a listener
for message events but the script "forgets" to call close() when the user
navigates away, then the resources it is consuming cannot be reclaimed.
There is a small chance that it may be reclaimed if the server terminates
the connection and a GC occurs before the UA is able to re-establish the
connection (i.e. during the reconnection delay or the reconnection), but I
don't think it's wise to rely on this as it would allow malicious scripts to
consume resource with no way for the user agent to recover.

The simplest way to prevent this would be to modify the condition in section
9 slightly to insist that the event listener is callable, drawing on the
text from HTML5's "Calling scripts" section 6.5.3.2#1.  i.e. modify the text
to say:

"An EventSource object with an open connection must not be garbage collected
if there are any event listeners registered for message events and at least
one of those listeners' global object is a Window object whose Document
object is fully active."

In other words, the automatic marking of the EventSource now requires that
at least one of the event listeners must be callable.  The only difference
that this makes, I *think*, is that pages in the history lose unreferenced
EventSource objects.  Is this true and would it actually be a problem?


-- 
Stewart Brodie
Software Engineer
ANT Software Limited



More information about the whatwg mailing list