-
-
Notifications
You must be signed in to change notification settings - Fork 635
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
OpenFailedError: TransactionInactiveError when using indexeddbshim + dexie #1126
Comments
Have you tried to transpile the tests down to ES5? (this is to avoid the incompability between native promises and the original IndexedDB spec, which is used by IDBShim) |
@dfahlander Targeting ES5 seems tricky; I'm running into some issues with more recent versions of TypeScript that seem to ignore/auto-include type definitions from ES6+ when I try to set I think microsoft/TypeScript#31649 is the same issue upstream. I'll try to figure out a bit more about what's going on here. |
You can also avoid using async/await instead of transpiling the code. The problem is that await calls makes the code return to come back in a later tick, and at that time IndexedDBShim has started believing that the transaction isn't being used anymore. Dexie will patch the global Promise within transactions so that those microticks occur in an emulated major tick that ensures IDB doesn't throw away the transaction but this only works if using Promise.prototype.then() etc, not async/await. When using native async/await things happen deep down in the browser engine that is not possible to control. |
Thanks @dfahlander - that makes sense. So the transpilation step is essentially introducing the use of the global I do like the convenience (and developer experience) of using Out of interest do you know if it's a tractable problem to handle that tick behaviour in |
Hrm. I do now believe I'm transpiling with ES5 as the target, and without pulling in any unnecessary type definitions (ensuring that I did encounter an error regarding a missing type declaration for The resulting {
"compilerOptions": {
"allowJs": true,
"lib": [ "es5", "es2015.promise" ],
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "es5",
"types": ["jquery", "mocha"]
},
...
} However the |
I think this is something to do with the unit test suite. I've noticed that this failure occurs in a particular test suite module that contains exactly two tests. If I remove either one of the tests, then the I'm going to close this with that finding, since it's enough of a discovery & workaround to allow me to continue. |
Despite a previous attempted workaround, I ran into this issue again after in another database-related unit test. This time I figured it'd be worth adding console debugging to try to determine the root cause. For reference, the test case I've been using writes a single record then performs a count on the table (expecting The error and stacktrace I've encountered for that test is:
By applying the changes illustrated in https://github.com/jayaddison/Dexie.js/commit/97b44c79262f01fe4d2a6a95cf6cd47eb8e7292e , I'm able to get the test to pass. I'll try to spend a bit more time to figure out exactly what those changes affect and why that appears to remedy the problem; I'm including the commit here in case it helps spark any ideas, and for later reference. Edit: update commit reference to point to fork repository, where it exists/originates |
This may somehow be related to
During test suite runs, that function is being called twice; the first time is during addon initialization at this line. The second call occurrence is initiated within the Removing the |
Could it be a bug that One idea is that This is illustrated as a commit by https://github.com/jayaddison/Dexie.js/commit/5711da31c3474c6c22caee6d80f53802b3bc9d37 Note that tests do not pass with this change alone. I think that something in |
The conflict mentioned previously appears to occur while the The change in https://github.com/jayaddison/Dexie.js/commit/46a412563511f69c29469e668837c076eb40faf3 (removing the I don't yet completely understand what's happening here. That operation occurs within a |
Debugging the value of Perhaps this is how the conflict occurs; the That's just a theory but might explain the behaviour? |
Edits: s/deadlock/conflict in previous comments.. the process does finish, but fails due to |
@dfahlander I think I've made some progress towards finding a root cause here, but it's still a bit approximate. There's some kind of conflicting interaction between the The addon performs some transactional operations on the I'm not completely sure why this is surfaced by usage of #1138 contains a potential fix that is 'working' here, although I'm not completely confident in it. |
Thanks @jayaddison! I haven't had a chance to deep dive into this issue yet. Looking at the PR, it seems to be ok except for that the code that reads and puts syncNodes isn't atomic anymore. Is the issue gone if you changed to: return Dexie.ignoreTransaction(() => db.transaction('rw', '_syncNodes', () => {
...
})
);
? |
@jayaddison I would like to deep dive into this (if/when get a little time over). Do you have any repro of the issue? |
@dfahlander Thanks - and yep, https://github.com/jayaddison/dexie-1126-repro now contains a minimal repro case for this. |
Unfortunately not, nope - I also tried passing the |
I'm adding some database-related unit test coverage for a Dexie-powered browser application written in JavaScript+TypeScript.
Unit tests are executed via
mochapack
(webpack
to compile the app followed bymocha
test execution), and to provide the IndexedDB API methods, an in-memoryindexeddbshim
instance is injected at test runtime.As a proof-of-concept I'd like to add a simple assertion on the output of
Table.count
for one of the database tables, and then build more complicated cases from there.I'm running into the following error/exception -- and have enabled
indexeddbshim
's DEBUG option to provide a bit more context:I've had a look at #712 and #701 (comment) -- the latter mentions that
Native async await can result in that a transaction is committed too early (which is also the case in Firefox. This is due to incompatiblity between IndexedDB(Shim) and the native Promise). Transpiled async await still fine.
-- and I wonder if that could be relevant to the problem here.I'd appreciate any assistance on how to investigate this further and any possible workarounds or fixes! I've been attempting some very basic debugging by editing the local
node_modules
directory copy ofdexie
and am glad to provide any other assistance figuring out the cause.The text was updated successfully, but these errors were encountered: