You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory corruption (SIGSEGV) when a future executing a sqlite query is aborted #1300
It seems there is some invalid memory access in the sqlite backend which sometimes happen when a future that is executing some query is aborted before it has chance to run to completion. Here is a minimal reproductible case:
(it might need to be run a couple of times before the bug is observed).
My hypothesis is that when the future is aborted, some sqlx objects might be dropped in unexpected order. e.g. a connection might be dropped before a statement handle, etc... which causes the underlying sqlite3 resources to be cleaned up in wrong order, causing an use-after-free or similar. I haven't verified this though.
Spent more time on this and I think I have an idea about what's going on. There seems to be a race condition between the StatementWorker and StatementResetter - sometimes the worker tries to step the statement at the same time the resetter tries to reset it which leads to memory corruption. An obvious fix would be to protect the statement pointer with a mutex, but perhaps there is a better way?
Yep, seem to be related. Although I don't think that PR fixes this issue because they still seem to be unconditionally resetting the statement in the resetter regardless of how many owners the underlying Arc has. But at least it seems to be a step in the right direction.
Activity
madadam commentedon Jul 6, 2021
Spent more time on this and I think I have an idea about what's going on. There seems to be a race condition between the
StatementWorkerandStatementResetter- sometimes the worker tries to step the statement at the same time the resetter tries to reset it which leads to memory corruption. An obvious fix would be to protect the statement pointer with a mutex, but perhaps there is a better way?andrewwhitehead commentedon Jul 6, 2021
Maybe related to this PR? #1186
madadam commentedon Jul 6, 2021
Yep, seem to be related. Although I don't think that PR fixes this issue because they still seem to be unconditionally resetting the statement in the resetter regardless of how many owners the underlying
Archas. But at least it seems to be a step in the right direction.Fix segfault due to race condition in sqlite (transact-rs#1300)
Fix segfault due to race condition in sqlite (#1300)
Fix segfault due to race condition in sqlite (#1300)
Fix segfault due to race condition in sqlite (#1300)
sqlite: fix a couple segfaults (#1351)
Merge launchbadge/sqlx master into JetASAP/sqlx master (#12)
Update ws-support (#15)