Re: [IndexedDB] Consider adding a completion event or callback to the IDBDatabase.close() operation (#72)

> Thus the wait time after blocked would be finite (I'm assuming that existing transactions would always complete or error?). Unless of course I'm missing something here again..?

Here's an example of a transaction that will run forever:

```js
var tx = db.transaction('s'), store = tx.objectStore('s');
(function spin() { store.get(0).onsuccess = spin; }());
```
Now that's a bad idea but it demonstrates that you can't guarantee that a transaction will complete in any given timeframe. (Halting Problem, etc)

> It seemed reasonable it could also be aborted it at "blocked"? 

Feature request tracked as #52 

> 1. How to actually cancel an open request? I assumed I knew how but now I realize I don't really?

As noted previously, you can't directly. You can do this:

```js
var open = indexedDB.open(name, ver);
open.onupgradeneeded = function() {
  open.transaction.abort(); // prevent upgrade, open will fail
};
open.onsuccess = function() {
  open.result.close(); // no upgrade, already opened; just close it
};
```

> 2. What exact event is triggered in chrome to signal on abrupt closing of the database (due to corruption, etc?) or is it just an error that appears when you try to start a transaction or open it?

`"close"` event (search for "forced flag" in the spec), and/or error via `"abort"` event fired at transaction. Depends on the timing of when the corruption (etc) is detected.

>  ...in this kind of pathological situations (software bugs or out-of-spec behavior) it seems like that would be the only thing to do.. (I mean the upgradeneeded event wouldn't even get triggered..)

Spec can't help you here, nor would we be likely to add functionality just to work around implementation bugs. Maybe someone has already reduced the specific error case and shared a workaround on e.g. StackOverflow ?

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/IndexedDB/issues/72#issuecomment-199890369

Received on Tuesday, 22 March 2016 16:28:10 UTC