Possible synchronisation issues
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the prepare(_:) implementation in QueryType.swift and trace how statement.next() is executed relative to the serial queue and caller thread. Determine whether the reported interleaving can cause the database corruption crash, then define a regression test and a fix or documented resolution for the synchronization issue.
Written by the indexing model from the issue text.
Description
Our app was facing a database corruption crash while reading from the database.
I was going through the implementation of SQLite.swift to check for possible synchronisation issues and found this piece of code.
// QueryType.swift
extension Connection {
public func prepare(_ query: QueryType) throws -> AnySequence<Row> {
let expression = query.expression
let statement = try prepare(expression.template, expression.bindings)
let columnNames = try columnNamesForQuery(query)
return AnySequence {
AnyIterator { statement.next().map { Row(columnNames, $0) } }
}
}
...
Each call to statement.next() is executed in a serial queue. But in between the two calls the code switches to the caller thread and leaves the database exposed to a sneaky write operation. This can potentially cause the subsequent statement.next() call to throw a corruption error.
@jberkel @NathanFallet Please check.
- Dominant language
- Swift
- Stars
- 10.2k
- Forks
- 1.6k
- Avg merge
- 6d 2h
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stephencelis/SQLite.swift
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
stephencelis/SQLite.swift#1375 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
stephencelis/SQLite.swift#1293 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
stephencelis/SQLite.swift#1347 · 7 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
stephencelis/SQLite.swift#1338 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
stephencelis/SQLite.swift#1337 · 3 comments ·
All issues in stephencelis/SQLite.swift
Similar issues
-
tvOS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
skiptools/skip-fuse-ui#147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OneBusAway/onebusaway-ios#1438 · 1 reaction ·