Skip to content

fatal error : disk I/O error (SQLITE_IOERR_VNODE) #630

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

Open
janhavi08 opened this issue Apr 12, 2017 · 16 comments
Open

fatal error : disk I/O error (SQLITE_IOERR_VNODE) #630

janhavi08 opened this issue Apr 12, 2017 · 16 comments

Comments

@janhavi08
Copy link

janhavi08 commented Apr 12, 2017

Hi, I have used stephencelis/SQLite.swift in our ios app developed in swift2. We are using this for sync since it is offline app. I am getting this error continuously since last 5 days. DB works well in first user login, when user logs out and login again and try to access db in the app fro any select / update / any db transaction, it crashes with the below error. On logout, we delete the sqlite file in document folder and on new login it recreates. Also, I gete database is locked error in between. Please help.

fatal error: 'try!' expression unexpectedly raised an error: disk I/O error: file /Library/Caches/com.apple.xbs/Sources/swiftlang_swift_2_2/swiftlang_swift_2_2-800.10.13/src/swift/stdlib/public/core/ErrorType.swift, line 54

@difoi
Copy link

difoi commented Apr 14, 2017

???????

@yasinkavakli
Copy link

Well a little bit more information or code where the exception raises would increase the chance to get help.

@AlexandrAmelchenko
Copy link

I faced similar problem in swift 3 after removal and recreation of sqlite file:

2017-10-20 19:18:18.680950 [311:39889] [INFO] {}[Database]: statement aborts at 20: [SELECT * FROM "season" WHERE (("deleted_at" IS ?) AND ("selected_by_user" = ?)) LIMIT 1] disk I/O error (Code 6922)

fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182

2017-10-20 19:18:18.684283 fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182
(lldb)

What information or code can be useful to you?

@yasinkavakli
Copy link

Did you created the database file?

You could post some code. Seems like try! raises an error because there is no database file.

@AlexandrAmelchenko
Copy link

It seems like database was successfully recreated because after its recreation we get few requests one by one - and the first of them are successfully performed.

Here's the code that falls:

func findSelectedByUser() throws -> DatabaseSeason? {
        let dbSeason = SeasonTable.table()
            .filter(SeasonTable.Column.deletedAt() == nil && SeasonTable.Column.selectedByUser() == 1)
            .limit(1)
        for row in try db.prepare(dbSeason) {
            if let season = SeasonDatabaseMapper().parseSingle(row: row) {
                return season
            }
        }
        return nil
    }

Crash appears in db.prepare(dbSeason).
Here's the code in which we create the database by user login:

private func connection() -> Connection {
        guard let dir = NSSearchPathForDirectoriesInDomains(.documentDirectory,
                .userDomainMask,
                true).first else {
            fatalError("Can't reach documents directory")
        }
        if let savedUser = UserDefaults.standard.string(forKey: "current_user_email") {
            databaseName = "\(savedUser).sqlite"
        } else {
            databaseName = "db0.sqlite"
        }
        let path = "\(dir)/\(databaseName)"
        log { path }

        guard let db = try? Connection(path) else {
            fatalError("Can't connect to database")
        }

        db.trace { message in
            log { message }
        }

        do {
            let manager = SQLiteMigrationManager(db: db, bundle: migrationsBundle())
            if !manager.hasMigrationsTable() {
                try manager.createMigrationsTable()
            }
            if manager.needsMigration() {
                try manager.migrateDatabase()
            }
        } catch {
            fatalError("Can't create database structure: " + error.localizedDescription)
        }

        return db
    }

Is there any other details that can be useful?

@yasinkavakli
Copy link

yasinkavakli commented Oct 23, 2017

Could you try to run a custom sql function instead of filtering on dbSeason? Just to see if you get what you want when working with sql.

https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md#custom-sql-functions

let stmt = try db.prepare("SELECT * FROM table WHERE ...")

@Bjorninn1
Copy link

Bjorninn1 commented Jun 5, 2018

I got the same error and it only showed up on my actual device and not in the simulator. The reason for the error was the location of the database file.

See solution here:

https://stackoverflow.com/a/50706384/5881884

@ghost
Copy link

ghost commented Jan 31, 2019

I tried to change database's location but still getting the error. @Bjorninn1 Have you encountered this problem again?

@Bjorninn1
Copy link

@berkerbilgi please check my updated answer on:

https://stackoverflow.com/a/50706384/5881884

@mikemee
Copy link
Collaborator

mikemee commented Oct 31, 2019

FWIW, some notes from my researching this 6922 extended error code. My iOS app gets this error sometimes while using a SQLite database read-only that is stored in the app bundle. It seems more frequent with iOS 13.

6922 is not a standard SQLite extended error. It's added by Apple and corresponds to SQLITE_IOERR_VNODE.

A Stack Overflow question asking about this same error is: https://stackoverflow.com/questions/43349189/what-does-sqlite-ioerr-vnode-mean

and that leads to the most definitive answer I could find, from the SQLite author at http://sqlite.1065341.n5.nabble.com/What-does-SQLITE-IOERR-VNODE-mean-td95250.html

SQLITE_IOERR_VNODE is an error code used by proprietary modifications to SQLite implemented by Apple for use on MacOS and iOS. I am told "The code indicates that a file relevant to the call was invalidated by a dispatch vnode source event" but I do not understand what that means.

Further speculation about that post is here: http://sqlite.1065341.n5.nabble.com/What-does-SQLITE-IOERR-VNODE-mean-tp95250p95255.html

TL;DR: It's some weird MacOS Virtual Node thing to do with memory-mapped files and "shouldn't be happening"...

This set of Apple slides, https://devstreaming-cdn.apple.com/videos/wwdc/2016/242vdhuk4hmwrxnb465/242/242_whats_new_in_core_data.pdf, referenced in the comments of the SO post above, has a slide with:

Screen Shot 2019-08-07 at 6 50 38 am

Perhaps someone with more than my (minimal!) Apple knowledge can speculate on the trigger conditions for this error and how to avoid them...

@simonfoxguitar
Copy link

I read all the above. I don't mean to be overly negative, but it does seem that error 10 means you're dead in the water. The above comments are not encouraging, and there's no rhyme or reason for the error to appear. It continues for 5 app restarts, then suddenly, we're not doing error 10 any more and everything is fine. And then the next day, it's error 10 again.
I've followed the documentation to the letter and ensured the threading is handled correctly. Would love to hear any practical advice other than giving up.

@mikemee
Copy link
Collaborator

mikemee commented Nov 7, 2019

I was able to workaround it by statically linking SQLite. See https://stackoverflow.com/questions/43349189/what-does-sqlite-ioerr-vnode-code-6922-mean/58668058

@mikemee
Copy link
Collaborator

mikemee commented Nov 7, 2019

@simonfoxguitar this started happening much more for me with ios13 and/or Xcode 11. See above.

@mikemee
Copy link
Collaborator

mikemee commented Nov 7, 2019

@simonfoxguitar also see the idea of adding the setting SQLITE_ENABLE_FILE_ASSERTIONS=1 to get more debug info. If you find something, please report back! I lost interest once static linking worked, but it would be nice to remove it from my workspace.

@simonfoxguitar
Copy link

simonfoxguitar commented Nov 7, 2019

Thanks Mikemee, thanks for the help, I'll give it some effort before giving up.
I have that library statically linked, will let you all know how it goes.

Also - did this problem only occur on simulators, or is it across real devices too?
Many thanks, appreciate the help greatly.

@mikemee
Copy link
Collaborator

mikemee commented Nov 7, 2019

Both simulator and a real device.

@jberkel jberkel changed the title fatal error : disk I/O error fatal error : disk I/O error (SQLITE_IOERR_VNODE) Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants