title: IndexedDB can make database unreachable (getting blocked), how unblock?
body: <p><strong>UPDATE</strong>
  I discovered the issue is that it's blocked. Despite the database always being created and upgraded by the same extension, it does not get closed. So now I'm getting the "onblocked" function called. </p>
  
  <p>How do I "unblock" currently blocked databases? And how do I prevent this in the future? This is an app, so no tabs are using it. And since I can't open those databases to even delete them (this also gets blocked), <strong><em>how do I close them?</em></strong></p>
  
  <p>(For anyone wondering, to avoid this issue from the start, you <strong>HAVE</strong> to do the folllowing:)</p>
  
  <pre><code>mydb.onversionchange = function(event) {
      mydb.close();
  };
  </code></pre>
  
  <p><strong>Original Post</strong></p>
  
  <p>IndexedDB dies and becomes unopenable if I (accidentally) try to open and upgrade with the wrong version. As far as I can tell, there's no way to ask indexedDB for the latest version of a DB. So if I try to run the following code twice, it destroys the database and it becomes unopenable:</p>
  
  <p><strong>And it never throws an error or calls onerror. It just sits silently</strong></p>
  
  <pre><code>var db = null;
  
  //Note, no version passed in, so the second time I do this, it seems to cause an error
  var req = indexedDB.open( "test" );
  req.onsuccess = function(event) { console.log( "suc: " + event.target.result.version ); db = event.target.result; };
  req.onerror = function(event) { console.log( "err: " + event ); };
  req.onupgradeneeded = function(event) { console.log( "upg: " + event.target.result.version ); };
  
  //We're doing in interval since waiting for callback
  var intv = setInterval(
      function()
      {
          if ( db === null ) return;
  
          clearInterval( intv );
  
          var req2 = indexedDB.open( "test", db.version + 1 );
          req2.onsuccess = function(event) { console.log( "suc: " + event.target.result.version ); };
          req2.onerror = function(event) { console.log( "err: " + event ); };
          req2.onupgradeneeded = function(event) { console.log( "upg: " + event.target.result.version ); };
      },
      50
  );
  </code></pre>
  
  <p>All of that code is in my <code>chrome.runtime.onInstalled.addListener</code>. So when I update my app, it calls it again. If I call <code>indexedDB.open( "test" )</code> without passing in the new version and then again run the setInterval function, it causes everything to become unusable and I'm never able to open "test" again. This would be solved if I could query indexedDB for the version of a database prior to attempting to open it. Does that exist?</p>