Search Unity

[UnityCache] indexedDB database could not be opened Error

Discussion in 'WebGL' started by Baraphor, Jul 18, 2018.

  1. Baraphor

    Baraphor

    Joined:
    Nov 16, 2016
    Posts:
    32
    Hello,

    What appears to be randomly we will get this error with all of our WebGL games, when this occurs the game will just progress to the end of the WebGL loading bar and then just get stuck and never load, which makes sense.

    Unfortunately I cannot reproduce it, it does happen randomly, nothing seems to stand out, expect that error message is always there.

    Has anyone figured out a way to fix this error?
     
  2. Picky-Salamander

    Picky-Salamander

    Joined:
    Apr 26, 2013
    Posts:
    27
    Hey,

    Yeah we've been having the issue as well. I just found out where this issue is (or where I think it is). It appears to be related to a issue in UnityLoader.js:

    Code (JavaScript):
    1. try {
    2.   var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
    3.   var openRequest = indexedDB.open(databaseName);
    4.   openRequest.onupgradeneeded = function (e) {
    5.     var objectStore = e.target.result.createObjectStore(store, { keyPath: "url" });
    6.     ["version", "company", "product", "updated", "revalidated", "accessed"].forEach(function (index) { objectStore.createIndex(index, index); });
    7.   };
    8.   openRequest.onsuccess = function (e) { initDatabase(e.target.result); };
    9.   openRequest.onerror = function () { initDatabase(null); };
    10.   setTimeout(openRequest.onerror, 1000);
    11. } catch (e) {
    12.   initDatabase(null);
    13. }
    The relevant line of code that is causing the issue is: setTimeout(openRequest.onerror, 1000). Basically, what seems to be happening is that the loader waits for IndexedDB to start up for 1 second then gives up. If the user has a slower machine this might happen. This will just cause PlayerPrefs to not save and data caching to fail. I think Unity fixed the data caching crash in the early 2018 releases, but the underlying issue still seems to exist.

    You can reliably reproduce the error if you put the below JavaScript on your page. It will delay IndexedDB opens by 5 seconds.

    Code (JavaScript):
    1. (function() {
    2.     var delegate = window.indexedDB.open;
    3.  
    4.     window.indexedDB.open = function(databaseName) {
    5.         var orgRequest = delegate.call(this, databaseName);
    6.  
    7.         var fakeRequest = {};
    8.  
    9.         orgRequest.onsuccess = function(e) {
    10.             fakeRequest.result = orgRequest.result;
    11.             setTimeout(function() {
    12.                 fakeRequest.onsuccess(e);
    13.             }, 5000);
    14.         };
    15.  
    16.         return fakeRequest;
    17.     };
    18. })();
    How to fix it (TLDR):

    I think you can avoid the issue by upgrading to the most recent version of Unity or turn off "data caching" in the publishing settings in WebGL's player settings (more info here).

    Either way though, the PlayerPrefs will stop working occasionally until Unity fixes the UnityLoader.js file. I'm pretty sure this issue still exists in Unity 2018.2. You could change UnityLoader.js to have a longer timeout, but that's kind of annoying to do (if you want to I can walk you through that process).
     
    nox_pp and IsmaeelShujat like this.
  3. Baraphor

    Baraphor

    Joined:
    Nov 16, 2016
    Posts:
    32
    Thanks,

    That is really useful.

    However for us it looks like the entire game fails to load, which is much worse than just not having player prefs, have you seen this happen as well?

    We are running our builds on Latest 2018.1, we have flipped to 2018.2 as we like to give a month for patches to come out.
     
  4. Picky-Salamander

    Picky-Salamander

    Joined:
    Apr 26, 2013
    Posts:
    27
    Yes. That's what I meant by the data cache crashing. I observed it in 2017.2, and I thought they fixed it in 2018.1, but maybe not? Try compiling with "data caching" turned off. This fixed the freeze in loading for us.

    If you want to force the IndexedDB failure so that you can test it, put the second piece of JavaScript from above into your web page.

    So this what I think is happening to you:
    1. IndexedDB takes too long to start and UnityLoader.js gives up loading IndexedDB.
    2. Data caching crashes, because IndexedDB didn't start.
    3. The loading routine freezes.
     
  5. Baraphor

    Baraphor

    Joined:
    Nov 16, 2016
    Posts:
    32
    Ok, Thanks I wasn't sure if that is what you meant, I am going to pass this along to our deployment dev and see if there is anything we can do about this.
     
  6. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    146
    What is "Data caching crashes, because IndexedDB didn't start" ?
    My Firefox version have bugs with IndexedDB and this unity code, related to "data caching" option, log to console "indexedDB database could not be opened", simple, and not crashes. Why it should crash?
     
  7. AntySK

    AntySK

    Joined:
    Aug 30, 2013
    Posts:
    31
    Same problem with Unity 2018.3 in Chrome
     
  8. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    I am getting this problem sometime while i am using unity 2018.9. I even unable to change the time duration in unityloader.js file because it is minified and i am unable to find the location of that syntax.
    Disabling data caching is not a suitable option i guess because it won't allow faster load. How you solve this issue?
     
  9. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    Hey did you solve the problem?
     
  10. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    Unityloader.js is a mini file, you can't edit the timeout time? how can you increase the time?

    I have updated to latest unity 2019.8.3 but it sometime get the problem.
     
  11. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    202
    Still happen even 2018.3.9f1 (Yesterday)

    The timeOut number should just be able to set from unity editor
     
  12. Edan-Smith

    Edan-Smith

    Joined:
    Jan 21, 2015
    Posts:
    23
    I'm having the same issue as well...
     
  13. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    202
    You can search for `setTimeout` function that has 1000 as a value
     
  14. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    I didn't find any setTimeout with 1000 value, there are several setTimeout in my unitylaoder.js like
    Code (CSharp):
    1. setTimeout(o.callback.bind(null,e,o),0)
    or
    etTimeout(a.onerror,1e3)
    but no time out with 1000 value. How did you get it?
     
  15. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    202
    @MFKJ 1e3 means 1000

    e means exponent which e3 is a notation for * 10^3
     
    Edan-Smith and MFKJ like this.
  16. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    Oh thanks, but it available on two places

    Code (CSharp):
    1. setTimeout(a.onerror,1e3)
    and
    Code (CSharp):
    1. setTimeout(r,1e3)
    where should i change and what should i write, the ideal value that dont produce the error?
     
  17. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    202
    > where should i change

    I don't know I replace both

    > the ideal value that dont produce the error

    Don't know too I just put 1e4 which is 10 sec. You might try 1e5
     
    Edan-Smith and MFKJ like this.
  18. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    Thanks for you help, i will implement it as you said but we still require a better and proper solution. If anyone found please share.
     
  19. Edan-Smith

    Edan-Smith

    Joined:
    Jan 21, 2015
    Posts:
    23
    MFKJ, just by doing that it solves the problem, right?

    Edit: Sounds like it worked for me.
     
    Last edited: Apr 14, 2019
  20. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    189
    Yeah by increasing the time, i never found any report that the problem is producing again. But i still searching for better and proper solution as you can forget to edit the compile code after build.
     
    nox_pp and Edan-Smith like this.
  21. Edan-Smith

    Edan-Smith

    Joined:
    Jan 21, 2015
    Posts:
    23
    Yeah... would be very cool if this was added as "Other Options" on WebGL build or something.
     
    MFKJ likes this.
  22. claytoncurmi

    claytoncurmi

    Joined:
    Jul 6, 2010
    Posts:
    138
    Hi all,

    I am facing the same issue using a client that was built with 2018.2.20f1. We only have two machines that are portraying this issue on Chrome (not in incognito mode). When we tried to launch the same build on Firefox it works as expected. It even runs on Chrome when in incognito mode. Following this thread recommendation we updated the timeout to 1e5 but the issue still occurs. Any ideas on how to go about this. I am also noticing that there a series of warnings saying;

    Code (CSharp):
    1. The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
    Such warnings do not appear on other machines. Chrome version is 74.0.3729.169

    Your help is appreciated.
     
    JamesArndt likes this.
  23. claytoncurmi

    claytoncurmi

    Joined:
    Jul 6, 2010
    Posts:
    138