In-memory stor drops statements if used between jobs
Bug report form
- [x] I have done a basic search of the issue tracker to find any existing issues that are similar.
- [x] I have checked that my version is at least the latest stable release available via my installation method.
Describe the bug
stor open can drop commands if it's used simultaneously between jobs. This can lead to data loss. This doesn't happen with file sqlite databases.
How to reproduce
# Extracting to a variable changes nothing, as last I checked stor open creates a new connection every time
# It could be and was multiple calls to stor open
let stork = stor open
$stork | query db "CREATE TABLE IF NOT EXISTS demoru (big BLOB)"
$stork | query db "INSERT INTO demoru (big) VALUES (?)" -p [(random binary 100mb)]
job spawn {
for i in 0..<10 {
$stork | query db "SELECT * FROM demoru" | collect
}
};
for i in 0..<10000 {
$stork | query db "INSERT INTO demoru (big) VALUES (?)" -p [(0x[01])]
}
$stork | query db "SELECT COUNT(*) FROM demoru"
Expected behavior
Lock until the other jobs are done with the memory db, have proper read parallelism, or just not silently fail to execute statements.
Configuration
| key | value |
|---|---|
| version | 0.108.0 |
| major | 0 |
| minor | 108 |
| patch | 0 |
| branch | |
| commit_hash | |
| build_os | windows-x86_64 |
| build_target | x86_64-pc-windows-msvc |
| rust_version | rustc 1.91.0 (f8297e351 2025-10-28) |
| rust_channel | stable-x86_64-pc-windows-msvc |
| cargo_version | cargo 1.91.0 (ea2d97820 2025-10-10) |
| build_time | 2025-11-09 20:13:32 -03:00 |
| build_rust_channel | release |
| allocator | standard |
| features | default, network, plugin, rustls-tls, sqlite, trash-support |
| installed_plugins | query 0.100.0 |
| experimental_options | example=false, reorder-cell-paths=true, pipefail=false, enforce-runtime-annotations=false |
I'd guess this was more of a problem with job spawn than stor. I'm not sure how stor is supposed to know it's being launched with job spawn and then behave differently if that happens. I could be wrong though.
@cosineblast any thought on this issue?
This seems a bit odd, I'll have a look at it. I hope a mutex can do the job.
Interestingly, if this issue is specific to jobs, then it's likely running this example without background jobs (but using par-each instead) should work correctly.
Ah mutable state, the root of all evil...
par-each also seems susceptible to it:
let stork = stor open
$stork | query db "CREATE TABLE IF NOT EXISTS demoru (big BLOB)"
$stork | query db "INSERT INTO demoru (big) VALUES (?)" -p [(random binary 100mb)]
0..<10000 | par-each { |i|
if $i mod 500 == 0 {
# comment to get 9981
$stork | query db "SELECT * FROM demoru" | collect
} else {
$stork | query db "INSERT INTO demoru (big) VALUES (?)" -p [(0x[01])]
}
} | ignore
$stork | query db "SELECT COUNT(*) FROM demoru"