Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide finer control over open request edge cases #223

Open
inexorabletash opened this issue Oct 26, 2017 · 1 comment
Open

Provide finer control over open request edge cases #223

inexorabletash opened this issue Oct 26, 2017 · 1 comment

Comments

@inexorabletash
Copy link
Member

inexorabletash commented Oct 26, 2017

A couple of scenarios:

Really blocked upgrades

  • Tab 1 opens a connection at v1
  • Tab 2 tries to open a connection at v2 - gets blocked (Tab 1 gets versionchange but can ignore it)
  • Tab 3 tries to open a connection at v2 as well; is in limbo state with no blocked event.

This limbo state falls out of the current spec. It's definitely unexpected, and not necessarily intentional, but that's how it works. I think one of the browsers (Firefox? Edge?) may have fired blocked here at one point.

Tab 3 can't give useful feedback to the user about what to do; it can only detect this with a timeout.

Should we fire blocked here?

Timed out upgrades

So let's say either Tab 2 or Tab 3 wants to defend against Tab 1 being a meanie and not closing the connection by using a timeout. Implementing this is subtle - the app needs to decide at some point that even if a subsequent upgradeneeded or success comes in then (1) the upgrade should not happen and (2) the connection should be closed, e.g.:

const open = indexedDB.open(name, version);
let abort_open = false;
setTimeout(() => { abort_open = true; }, 1000); // give up after 1s
open.onblocked = e => {
  if (abort_open) return;
  // normal blocked handler here
};
open.onupgradeneeded = e => {
 if (abort_open) { open.transaction.abort(); e.target.result.close(); return; }
 // normal upgradeneeded handler here
};
open.onsuccess = e => {
  if (abort_open) { e.target.result.close(); return; }
  // normal success handler here
};

Otherwise you run into problems like https://stackoverflow.com/questions/40032008/how-should-an-app-react-when-indexeddb-is-blocked

Should timeouts be built in? Or tie into AbortController or other ways to abort the open request?

@dmurph
Copy link

dmurph commented Sep 20, 2019

TPAC 2019 Web Apps Indexed DB triage notes:

I think it's reasonable to alert new connection requests that there is a current connection that is blocking new connections. This could happen for both new requests for the same version, as well as higher versions.

I don't write specs, but I could imagine this done as :

When the onblocked event is triggered, the system stores the version at which it was blocked for that database, and when new connection are created, they can check this state. the state would be cleared when the connection for that version is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants