Search Unity

[UnityCache] indexedDB database could not be opened Error

Discussion in 'Web' 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:
    167
    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:
    33
    Same problem with Unity 2018.3 in Chrome
     
  8. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    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:
    264
    Hey did you solve the problem?
     
  10. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    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:
    1,168
    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:
    27
    I'm having the same issue as well...
     
  13. Thaina

    Thaina

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

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    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:
    1,168
    @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:
    264
    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:
    1,168
    > 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:
    264
    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:
    27
    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:
    264
    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:
    27
    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:
    168
    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:
    168
  24. IOU_RAY

    IOU_RAY

    Joined:
    Jul 25, 2017
    Posts:
    127
    bumper cars...yes we are running into this issue as well. Anyone at Unity to look into this?
     
  25. IOU_RAY

    IOU_RAY

    Joined:
    Jul 25, 2017
    Posts:
    127
    Lots of our users are running into the issue... Requiring users (our customers) to clear cache/hard refresh when this happens is pretty silly, but perfectly representative of Unity these days.
     
    Last edited: Dec 23, 2019
  26. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    The setTimeout(1000) timeout handler was originally added to work around browser bugs in Safari 9 and Firefox 45 and older. Since then the relevant browser bugs have been fixed, and the timeout has been removed in Unity 2019.2.0a10 and newer Unity versions.
     
    IOU_RAY and Thaina like this.
  27. IOU_RAY

    IOU_RAY

    Joined:
    Jul 25, 2017
    Posts:
    127
    Thanks. I guess we will be aiming for 2019 stable release very soon then. Appreciate the response at least.
     
  28. dangerPanda

    dangerPanda

    Joined:
    Oct 9, 2019
    Posts:
    6
    I see this error in 2019.3.13f1 in chrome and firefox
     
  29. Markus64

    Markus64

    Joined:
    Feb 5, 2019
    Posts:
    1
  30. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Hmm, if you are still observing this issue, please make a bug report along with the browser environment information and a repro. According to our bug database this issue is expected to have been fixed in 2019.2.0a10 and newer.
     
  31. moskalpj

    moskalpj

    Joined:
    Sep 5, 2020
    Posts:
    1
    I've been running into the web loading problem too (Version 2020.1.4f1) what has helped me to solve the issue was selecting Decompression Fallback (to true) in the Publishing Settings of the player. I hope that helps.
     
    lucho_xxx07 likes this.
  32. Amalaryk

    Amalaryk

    Joined:
    Nov 14, 2013
    Posts:
    7
    Thanks for sharing moskalpj, but it didn't work for me in 2020.2.2f :(

    I have extremely simple project (a prototype, less then 500 LOC, no 3rd paty libraries) that refuses to load in incognito mode on any tested browser (Firefox and Chrome-based browsers)
     
  33. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    @moskalpj @Amalaryk Enabling Decompression Fallback should not affect the issue that this is about (not being able to open IndexedDB database). I would recommend trying out latest 2021.1 alpha version, since we landed new Development time log messaging there to help diagnose project load issues. Maybe one of those messages would trigger and give clues.

    If not, if you can host the project somewhere, maybe someone on the forums will be able to try out and give a hint about what might be going wrong. Did the web console log print any messages?
     
  34. Amalaryk

    Amalaryk

    Joined:
    Nov 14, 2013
    Posts:
    7
    Thanks @jukka_j for your response!

    All I see in the log is this:
    After trying Unity 2021.1.0b4 (newest 2021 available in UnityHub)

    I got:

    Which I think is identical
     
  35. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
  36. Amalaryk

    Amalaryk

    Joined:
    Nov 14, 2013
    Posts:
    7
    Last edited: Feb 5, 2021
  37. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    110
    Getting the same issue on Unity 2020.3.2f1 web build on one person's machine. Thanks for the info I will try the workaround.
     
  38. dw_choi

    dw_choi

    Joined:
    Jun 4, 2021
    Posts:
    1
    Still happening on 2022.2.13.
    Modification methods in connected threads now appear to be invalid.

    [UnityCache] Failed to load 'http://s-dev.rubixx.me/StreamingAssets/aa/WebGL/eventsys(local)_assets_all_e50c05d963b01bdaf7ec8dd759f78cf3.bundle' from indexedDB cache due to the error: Error: Could not connect to cache: Cache API is not supported.
     
  39. thelocationlabdeveloper

    thelocationlabdeveloper

    Joined:
    Sep 8, 2020
    Posts:
    18
    Did you find the solution of it?
     
  40. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    @jukka_j
    Happening now in Unity 2021.3.32f1, Microsoft Edge 121.0.2277.83 (Official build) (64-bit)
    Options on:
    Exceptions, Brotli compression, data caching, hash file names
     
    Last edited: Jan 30, 2024
  41. HamidMac

    HamidMac

    Joined:
    Sep 18, 2019
    Posts:
    16
    I just get the same message with Unity 2022, however, my problem is with the loading of my addressable, which seems to load in the network tab of Chrome, yet my game freezes, it is random, sometimes just with one refresh the issue solves, sometimes it is persistent!!
    [UnityCache] '' successfully downloaded but not stored in the indexedDB cache due to the error: NetworkError: Cache.put() encountered a network error