-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Unofficial fork: help with segmentation fault (core dumped) #368
Comments
I can confirm that your code causes a |
The following command returns a different error message: npm run rebuild-debug && npm t
...
integrity checks
Database#prepare()
1) while iterating (allowed)
Assertion failed: (!db->GetState()->busy), function Statement, file ./src/objects/statement.lzz, line 70.
[1] 32448 abort npm t |
I think maybe a BDD approach is good for this feature where we add the failing test case first and then rework the code to make it pass, rather than making loads of changes to the code and hoping it has the desired effect without breaking anything else. As it stands right now the What functionality are you trying to achieve? |
Reading and writing from within the implementation of a user-defined function (#338) which seems to be allowed #338 (comment) Here's a new idea: what if we move From an API point of view two versions come to mind:
Similar to
Thanks to everything being synchronous we can declare an unsafe block // You cannot do nasty things here
db.unsafe(() => {
// You can do nasty things here
});
// You cannot do nasty things here If we implement this we need to make sure that nested Both solutions by itself don't solve the segfault though. But I think they're the right way nonetheless. |
Here's a separate comment regarding the segfault: I guess the assertion just needs a |
I can't get more useful errors even with Does anything change for you when you update the line? assert(!db->GetState()->busy || db->GetState()->unsafe_mode); |
I just added a test for my use-case in 7ad0b19, could you please provide something similar so I can understand what you're doing and reproduce it easily? |
When I pull you code and run Are you sure you're generating the
|
If I remove that line as such then the test output is the same as the one you first posted: ➜ better-sqlite3 git:(segfault) ✗ git diff src/objects/statement.lzz
diff --git a/src/objects/statement.lzz b/src/objects/statement.lzz
index 163d069..f0a65c0 100644
--- a/src/objects/statement.lzz
+++ b/src/objects/statement.lzz
@@ -67,7 +67,6 @@ private:
assert(db != NULL);
assert(handle != NULL);
assert(db->GetState()->open);
- assert(!db->GetState()->busy);
db->AddStatement(this);
}
|
I think I've caught a cold and I'm lacking big brain energy right now. I'll get back to you when I can. Maybe you can put some thought into the unsafe-block I've suggested above. |
Changed the title so thousands of people who use |
Heya, so I had a bit of time to think about whether unsafe-mode is set during instantiation for the whole connection or variable per-statement and the conclusion I came to is... yes, function-scoped enable/disable sounds preferable 😄 The unsafe mode is intended for use-cases such as mine and yours, so naturally the semantics of it should allow for both methods. I think the cons for your approach are fairly minor:
And the pros:
|
In all honesty I will probably not find the time to rewrite unsafe mode to change how it operates but I'm happy to assist others from my own limited experience with the code 😸 |
meh, I had a crack at it master...missinglink:unsafe_statement |
@missinglink Nice! I'm not a fan of the second argument either, because it is much less explicit (and flexible?) than the approach in your PR or the unsafe-block. I'd even accept calling the block Anyway, your two approaches get us closer to the solution. I haven't done any native Node.js stuff yet, so I will give it a shot as well. If things go well I'll open a PR today and we have something to discuss.
@JoshuaWise thanks, that didn't cross my mind |
Yeah, I diverged from the plan once I got into the code, I think the semantics you suggested are better but tacking it on to I actually have zero experience with c++ so I'm just making it all up as I go along 🤷♂️ Another option is a 'namespace', so |
Regarding the naming, I was going to write up something about what is/isn't going to be accepted for inclusion into The tl;dr is that anything that can SEGFAULT or corrupt your database will never be included but things that result in undefined behaviour may be included. So based off that we need to pick a word that indicates caution but not as far as to make people thing it can corrupt the database or crash their application. |
💯 |
One problem with that definition is that I believe my use-case will memory leak in certain situations and crash with OOM errors, so there's that.. |
Closing now that unsafe mode is available in v7.0.0 |
This just randomly came up while I was working on tests for #367 (cc @missinglink). All I did was make slight changes to the
missinglink:unsafe_mode
branch. I haven't dug deeper but I assume a segfault is always bad and my changes kind of did a fuzzing? Now the question is: did I unravel an existing bug or canunsafe
actually cause a segfault? Which would be a heckin bold UNSAFE if I've ever seen one 😄Steps to reproduce:
git clone --single-branch --branch segfault [email protected]:Prinzhorn/better-sqlite3.git
cd better-sqlite3
npm install
npm test
The text was updated successfully, but these errors were encountered: