You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.:
constopen=indexedDB.open(name,version);letabort_open=false;setTimeout(()=>{abort_open=true;},1000);// give up after 1sopen.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};
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.
A couple of scenarios:
Really blocked upgrades
blocked
(Tab 1 getsversionchange
but can ignore it)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
orsuccess
comes in then (1) the upgrade should not happen and (2) the connection should be closed, e.g.: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?The text was updated successfully, but these errors were encountered: