<?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>23878</bug_id>
          
          <creation_ts>2013-11-20 22:03:31 +0000</creation_ts>
          <short_desc>Define a fetch registry</short_desc>
          <delta_ts>2016-08-24 13:32:53 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>Fetch</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Hallvord R. M. Steen">hsteen</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>annevk</cc>
    
    <cc>bkelly</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>igrigorik</cc>
    
    <cc>jungkees</cc>
    
    <cc>mike</cc>
    
    <cc>mkwst</cc>
    
    <cc>public-webapps</cc>
    
    <cc>tyoshino</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>sideshowbarker+fetchspec</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>96603</commentid>
    <comment_count>0</comment_count>
    <who name="Hallvord R. M. Steen">hsteen</who>
    <bug_when>2013-11-20 22:03:31 +0000</bug_when>
    <thetext>In https://github.com/whatwg/xhr/pull/3 annevk says &quot;I guess we&apos;ll have to decide what kind of fetch termination happens here though.&quot;. This bug is just a reminder to make that decision happen.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96628</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-11-21 11:38:33 +0000</bug_when>
    <thetext>So I guess this is about better defining what happens in http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#abort-a-document

I guess if that terminates with fatal it&apos;s best because that effectively kills XMLHttpRequest the quickest.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106572</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-05-21 14:30:00 +0000</bug_when>
    <thetext>Ideally the way this is fixed is that Ian tracks all fetches for a given global/document and just terminates them all. We then just hook into that pool of fetches. Assigning to Ian for consideration.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>112421</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-09-29 21:19:51 +0000</bug_when>
    <thetext>How can I track what fetches happen for a given document/global/environment settings object? Is that a property of a fetch such that I can just reference &quot;every instance of the fetch algorithm whose foobar is baz&quot;?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>112422</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-09-29 21:20:19 +0000</bug_when>
    <thetext>(might be best to just use the document unload steps or some such, on the fetch side, though I guess that doesn&apos;t help with workers)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113173</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-15 08:11:24 +0000</bug_when>
    <thetext>No that is not a property of Fetch. And note that we need historical tracking too. E.g. if we ever want to define https://w3c.github.io/web-performance/specs/ResourceTiming/Overview.html properly. Or the idea discussed in https://github.com/w3c/navigation-timing/issues/3

Now we could make Fetch append to some list of the environment settings object to track these things.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113237</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-10-15 19:04:55 +0000</bug_when>
    <thetext>I don&apos;t understand why this isn&apos;t a property of Fetch. Isn&apos;t this something that happens regardless of the environment? Say someone invents a new one, like Service Workers or something. Don&apos;t we need to also define lifetime rules there?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113278</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-16 07:55:45 +0000</bug_when>
    <thetext>This is a property likely shared by all environments, yes. You define the environment settings object. It would make some sense to register lifetime things there.

Fetch at the moment deals with fetching. It could also extend the environment settings object and start doing logging (effectively), but I&apos;m not convinced that&apos;s a good idea.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113328</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-10-16 16:30:13 +0000</bug_when>
    <thetext>How is the lifetime of a fetch not part of fetching? I really don&apos;t understand what the environment settings object would have here. It&apos;s just a struct, it doesn&apos;t have behaviour.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113333</commentid>
    <comment_count>9</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-16 16:39:51 +0000</bug_when>
    <thetext>Various features require tracking all fetches originating from an environment settings object&apos;s global object (or responsible document). So e.g. if I have

  &lt;!doctype html&gt;
  &lt;img src=...&gt;
  &lt;script src=...&gt;

this list would contain two resources and perhaps a special entry for the document itself. This list would then be used when the document is closed somehow to terminate ongoing fetches. It would also be used to report timing information (see all the stuff the web performance group introduces without solid normative language around it).

This seems out of scope for Fetch, which deals with the life cycle of a single fetch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113406</commentid>
    <comment_count>10</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-10-17 23:48:41 +0000</bug_when>
    <thetext>The life cycle of a single fetch is exactly what we&apos;re talking about here.
Fetch should just add each fetch to some per-environment-settings-object list when it starts, and remove each fetch when it ends, and if any are left over when the document goes away it should abort them (except for those it shouldn&apos;t abort, like images).

If you need hooks for when a settings object is going away, that I can provide, but the lifecycle management seems like something that entirely belongs in Fetch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113412</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-18 09:20:30 +0000</bug_when>
    <thetext>If I remove from the list, how would we define e.g. http://www.w3.org/TR/performance-timeline/#dom-performance-getentries properly? I specifically wrote down that this list was used for other things than terminating ongoing activity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113499</commentid>
    <comment_count>12</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-10-20 21:44:55 +0000</bug_when>
    <thetext>Well you don&apos;t have to actually remove it, you could just not do anything with fetches that are already done when you go through the list at shutdown time.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113523</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-21 07:37:01 +0000</bug_when>
    <thetext>Okay, so the idea is that we add a list to the environment settings object that tracks all Request/Response for that environment settings object.

That list can then be used for various performance features.

When the environment settings object goes away, HTML pings Fetch and Fetch terminates any ongoing operations within that list, likely triggering some more events inside the environment settings object&apos;s global object and then it&apos;s done.

Sounds about right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113547</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-10-21 22:50:47 +0000</bug_when>
    <thetext>Well I wouldn&apos;t trigger any events, and you need to skip terminating those that are magical like &lt;img&gt;, but yeah, basically.

You can do the list entirely in Fetch. Just say &quot;Each environment settings object is associated with a list of fetch algorithm instances...&quot; or whatever. Or, have each fetch associated with a settings object, then refer to &quot;all the fetches associated with this settings object...&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114230</commentid>
    <comment_count>15</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-10-30 11:29:37 +0000</bug_when>
    <thetext>I&apos;m not a big fan of taking all that on in Fetch, but since nobody else is volunteering, will investigate.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118010</commentid>
    <comment_count>16</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-02-18 14:08:41 +0000</bug_when>
    <thetext>So here is my tentative plan:

* Introduce a &quot;fetch registry&quot;. It has a 1:1 relation with environment settings objects.
* Introduce &quot;fetch records&quot; that keep track of a fetch. The fetch algorithm creates these and appends them to the registry. They stay there for the lifetime of the environment settings object, so we can explain resource timing and such through it.
* Introduce a &quot;keep-alive flag&quot; to explain &lt;img&gt;, ping=&quot;&quot;, and sendBeacon().
* When an environment settings object goes away (navigation, termination) all fetch records that have an active fetch and no keep-alive flag will have their fetch terminated. Hopefully environment settings objects will get some kind of callback hook for this.

Once this is in place we can potentially move some things from request to fetch records (e.g. &quot;redirect count&quot;).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118094</commentid>
    <comment_count>17</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-02-23 17:14:41 +0000</bug_when>
    <thetext>https://gist.github.com/annevk/5496188</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>120896</commentid>
    <comment_count>18</comment_count>
    <who name="Ilya Grigorik">igrigorik</who>
    <bug_when>2015-06-10 23:44:30 +0000</bug_when>
    <thetext>A couple of requirements/notes that have come up in context of Fetch registry:

1) I&apos;d be nice if there was an ~observer API that allowed an application to be notified when new fetch requests are added to the registry - see discussion in [1]. As a related question: when would fetch objects be made visible, when the request is initiated? If so, then that would be sufficient to solve the use case in [1], and if not then we&apos;d have to investigate alternative routes.

2) For cases where the fetch goes through one or more redirects, it should be possible to see the full route - see [2]. That is, each request in the redirect chain as a separate fetch, plus a way to link them together. 

[1] https://github.com/w3c/performance-timeline/issues/13#issuecomment-108097288
[2] https://github.com/w3c/preload/issues/14</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>120898</commentid>
    <comment_count>19</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-06-11 05:09:51 +0000</bug_when>
    <thetext>We cannot expose redirects: https://fetch.spec.whatwg.org/#atomic-http-redirect-handling</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>120907</commentid>
    <comment_count>20</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-06-11 14:47:14 +0000</bug_when>
    <thetext>https://github.com/whatwg/fetch/commit/744d8b3bbe3b59492cff5f0fdd49b8dd053c4571 addresses this per comment 16. For now I have not moved things from request to fetch records. Fetch records simply hold a pointer to request. We can move things around later if that makes sense for the API.

Ian, will you make sure HTML invokes https://fetch.spec.whatwg.org/#concept-fetch-registry-terminate at the right time?

Jungkees, service workers also needs to invoke that hook when a service worker dies. Unless you reuse some worker / shared worker infrastructure from HTML for that.

Ilya, we should probably discuss the details of the observer API on GitHub. This bug is mostly about setting up the underlying infrastructure.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121207</commentid>
    <comment_count>21</comment_count>
    <who name="Jungkee Song">jungkees</who>
    <bug_when>2015-06-18 06:09:11 +0000</bug_when>
    <thetext>&gt; Jungkees, service workers also needs to invoke that hook when a service worker dies. Unless you reuse some worker / shared worker infrastructure from HTML for that.

Service workers are reusing &quot;terminate a worker&quot; algorithm in HTML.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127223</commentid>
    <comment_count>22</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-08-24 13:32:53 +0000</bug_when>
    <thetext>https://github.com/whatwg/fetch/issues/81 is the successor to this issue.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>