{"action":"created","issue":{"url":"https://api.github.com/repos/localForage/localForage/issues/846","repository_url":"https://api.github.com/repos/localForage/localForage","labels_url":"https://api.github.com/repos/localForage/localForage/issues/846/labels{/name}","comments_url":"https://api.github.com/repos/localForage/localForage/issues/846/comments","events_url":"https://api.github.com/repos/localForage/localForage/issues/846/events","html_url":"https://github.com/localForage/localForage/issues/846","id":359554278,"node_id":"MDU6SXNzdWUzNTk1NTQyNzg=","number":846,"title":"_tryReconnect, forage._dbInfo is null (caused by Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.)","user":{"login":"eugeniumegherea","id":25582225,"node_id":"MDQ6VXNlcjI1NTgyMjI1","avatar_url":"https://avatars2.githubusercontent.com/u/25582225?v=4","gravatar_id":"","url":"https://api.github.com/users/eugeniumegherea","html_url":"https://github.com/eugeniumegherea","followers_url":"https://api.github.com/users/eugeniumegherea/followers","following_url":"https://api.github.com/users/eugeniumegherea/following{/other_user}","gists_url":"https://api.github.com/users/eugeniumegherea/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeniumegherea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeniumegherea/subscriptions","organizations_url":"https://api.github.com/users/eugeniumegherea/orgs","repos_url":"https://api.github.com/users/eugeniumegherea/repos","events_url":"https://api.github.com/users/eugeniumegherea/events{/privacy}","received_events_url":"https://api.github.com/users/eugeniumegherea/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-12T16:13:53Z","updated_at":"2018-12-11T06:19:40Z","closed_at":"2018-09-21T13:46:17Z","author_association":"NONE","body":"Using localforage 1.7.2 on chrome 69 \r\nIn a angular 2 application of ours (where a database can have at least 30 stores), I found a pattern to reproduce `Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.` 100% of the times.\r\n\r\nI want to share what I've found so far:\r\n- To reproduce I basically do a 'Clear storage' from chrome dev tools and refresh the page.\r\n- The error is magically gone on the next page refresh\r\n- There is an `InvalidStateError` (see images), which calls `_tryReconnect` https://github.com/localForage/localForage/blob/3e1d6e70a001e0f057d816740c7bc9167e2f0711/dist/localforage.js#L792\r\n- In `_tryReconnect` function, for some reason, in loop, `forage._dbInfo` is null, which throws `TypeError: Cannot read property 'db' of null` (see images)\r\nhttps://github.com/localForage/localForage/blob/3e1d6e70a001e0f057d816740c7bc9167e2f0711/dist/localforage.js#L757\r\n- Tried to handle `forage._dbInfo` null, but the same error (cannot read db of null) happened in other part of the code\r\n- At this point, I think the issue might hide in race conditions and fast concurrent `localforage.createInstance` and writing to that store. (We have a kind of sync mechanism, which recreates IDB state from API, so we basically create multiple stores at the same time)\r\n\r\nDo you have any ideas what this may be?\r\nThanks\r\n\r\nFailed to execute 'transaction' on 'IDBDatabase': The database connection is closing\r\n![screen shot 2018-09-12 at 6 17 00 pm](https://user-images.githubusercontent.com/25582225/45437105-f082a200-b6bc-11e8-8dee-b77333490fc3.png)\r\n![screen shot 2018-09-12 at 6 18 05 pm](https://user-images.githubusercontent.com/25582225/45437216-19a33280-b6bd-11e8-99f3-a2b6cea692ed.png)\r\n\r\nSee contents of `dbContext` object\r\n![screen shot 2018-09-12 at 6 23 29 pm](https://user-images.githubusercontent.com/25582225/45437407-6ab32680-b6bd-11e8-9e4e-090da5fd4a4c.png)\r\n\r\nSee contents of each `forage` from `forages` array\r\n![screen shot 2018-09-12 at 6 28 25 pm](https://user-images.githubusercontent.com/25582225/45437475-8caca900-b6bd-11e8-83f9-60cb8fe2e98e.png)\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/localForage/localForage/issues/comments/446086076","html_url":"https://github.com/localForage/localForage/issues/846#issuecomment-446086076","issue_url":"https://api.github.com/repos/localForage/localForage/issues/846","id":446086076,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NjA4NjA3Ng==","user":{"login":"korlend","id":19622434,"node_id":"MDQ6VXNlcjE5NjIyNDM0","avatar_url":"https://avatars3.githubusercontent.com/u/19622434?v=4","gravatar_id":"","url":"https://api.github.com/users/korlend","html_url":"https://github.com/korlend","followers_url":"https://api.github.com/users/korlend/followers","following_url":"https://api.github.com/users/korlend/following{/other_user}","gists_url":"https://api.github.com/users/korlend/gists{/gist_id}","starred_url":"https://api.github.com/users/korlend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/korlend/subscriptions","organizations_url":"https://api.github.com/users/korlend/orgs","repos_url":"https://api.github.com/users/korlend/repos","events_url":"https://api.github.com/users/korlend/events{/privacy}","received_events_url":"https://api.github.com/users/korlend/received_events","type":"User","site_admin":false},"created_at":"2018-12-11T06:19:40Z","updated_at":"2018-12-11T06:19:40Z","author_association":"NONE","body":"I had the same issue.\r\nWhen I subscribe on .ready of localforage storage, and then call .setItem it cause error. So I wrote my own ready promise.\r\n```javascript\r\n  onready () {\r\n    if (this._ready) {\r\n      return new Promise((resolve, reject) => resolve(true))\r\n    } else {\r\n      return new Promise((resolve, reject) => {\r\n        this._localForageCollection.ready(() => {\r\n          const repeater = () => {\r\n            if (this._localForageCollection._dbInfo) {\r\n              resolve(true)\r\n              this._ready = true\r\n              return\r\n            } else {\r\n              const tm = setTimeout(repeater, 500)\r\n              clearTimeout(tm)\r\n            }\r\n          }\r\n          repeater()\r\n        })\r\n      })\r\n    }\r\n  }\r\n```"}}
{"actor":{"display_login":"korlend"}}