<?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>22540</bug_id>
          
          <creation_ts>2013-07-02 22:09:20 +0000</creation_ts>
          <short_desc>Fire event when database connection is closed without explicit close() call</short_desc>
          <delta_ts>2015-04-02 21:43:56 +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>Indexed Database API</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joshua Bell">jsbell</reporter>
          <assigned_to name="This bug has no owner yet - up for the taking">dave.null</assigned_to>
          <cc>cmumford</cc>
    
    <cc>israelh</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>90157</commentid>
    <comment_count>0</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2013-07-02 22:09:20 +0000</bug_when>
    <thetext>NOTE: the following is a proposal for a future version of IndexedDB

Just as an event is fired at a transaction when the transaction implicitly aborts (but not when abort() is called), there are cases where a database connection may close even without close() being called, and script should be notified with an event.

Scenarios:

* the user invokes the browser&apos;s &quot;clear my stored data&quot; option which deletes the backing store

* backing store is on a removable storage medium; the browser detects when the medium is removed and further read/write attempts to the database will fail (while file handles will be lost, arguably the implementation could do some magic in this scenario to reestablish the connection behind the scenes, simply failing any attempted transactions with UnknownError in the mean time)

Proposal:

If the connection to the database is closed other than by a call to close():
1. set the /closePending/ flag of /transaction/
2. for each transaction created using /connection/ that is not complete, run the steps for aborting the transaction with /transaction/ and &quot;AbortError&quot;
3. fire a &quot;connectionclosed&quot; event at /connection/; the event does not bubble and is not cancelable</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90162</commentid>
    <comment_count>1</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2013-07-02 22:23:28 +0000</bug_when>
    <thetext>FWIW, various other things in the platform already fire &quot;close&quot; events; given that this event is fired at a connection object, that&apos;s probably a bettername.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90183</commentid>
    <comment_count>2</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2013-07-02 23:32:36 +0000</bug_when>
    <thetext>step 1 should be: set the /closePending/ flag of /connection/

Also, it should be made clear that this does not apply to connections closed via GC, context destruction, etc.

Thanks, Kyle!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>90681</commentid>
    <comment_count>3</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2013-07-12 19:20:15 +0000</bug_when>
    <thetext>One bit of developer feedback already - this should include a message indicating the reason for the closure. (e.g. user deleted the backing store, I/O error, etc)

There&apos;s no generic |message| property on Event, so either we need to define a custom Event type or add one to DOM Event.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100820</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Mumford">cmumford</who>
    <bug_when>2014-02-18 23:01:11 +0000</bug_when>
    <thetext>Regarding Josh&apos;s suggestion for a closure reason, here&apos;s my proposal.

== Scenarios ==

Use case #1 - Normal closure caused by page

In this case the web page will:

1. Open a connection to database.
2. Register a close event handler.
3. Optionally read/write data from/to the database.
4. Script calls close() on the IDBDatabase connection object.

Use case #2 - Normal closure caused by browser

In this case the web page will:

1. Open a connection to database.
2. Register a close event handler.
3. Optionally read/write data from/to the database.

When the database is open the user will then:

1. Display browser settings.
2. Choose to clear client data (like &quot;Clear cookies and other site data&quot;).

In this use case the page did not initiate the closure.

Use case #3 - Error in backing store forced closure.

In this case the web page will:

1. Open a connection to database.
2. Register a close event handler.
3. Read/write data from/to the database.

During the execution of the reads/writes in step #3 the backing store encountered an error which requires the connection to be closed.

== Proposal ==

The proposed solution is to fire a &quot;close&quot; event at the IDBDatabase object, as previously suggested, but the event will implement the new IDBConnectionCloseEvent interface

interface IDBConnectionCloseEvent : Event {
    readonly    attribute DOMString      reason;
    readonly    attribute DOMString      message;
};

The values for these attributes are as follows.

reason:
-------
&quot;closed&quot;
&quot;user&quot;
&quot;error&quot;

message:
--------
This would contain any additional information the browser may want to supply. Some examples might be:

  &quot;Closed by page&quot;
  &quot;Deleted all user data&quot;
  &quot;Database corrupt: Checksum mismatch&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102708</commentid>
    <comment_count>5</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2014-03-20 18:42:00 +0000</bug_when>
    <thetext>Any opinions on cmumford&apos;s proposal?

Chrome is already firing a close event in the abnormal case per my description (and refined by comments 1-2), but it doesn&apos;t introduce a new type to the platform and since it&apos;s abnormal-close only it can&apos;t be relied upon by pages.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119183</commentid>
    <comment_count>6</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2015-04-01 22:31:39 +0000</bug_when>
    <thetext>Pinging again - any opinions from other implementers?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119184</commentid>
    <comment_count>7</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2015-04-01 22:37:21 +0000</bug_when>
    <thetext>I don&apos;t have an opinion on the whole &quot;reason&quot;/&quot;message&quot; discussion. Similar attempts in other APIs have so far been failures. Dominic Denicola is a good person to talk to here.

But that aside, a &quot;close&quot; event on connections, as well as the transaction abort handling sounds good to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119206</commentid>
    <comment_count>8</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2015-04-02 21:43:56 +0000</bug_when>
    <thetext>I took a stab at specifying this in:

https://github.com/w3c/IndexedDB/commit/6bce2d57d5ac9dbfc68c24a69396217cdd5bfa0a

TL;DR:

If connection closes abnormally, abort any outstanding transactions, then fire &quot;close&quot; at the IDBDatabase. No reason/message.

(This matches the behavior shipping in Chrome.)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>