firebase-ios-sdk: Incorrect long values storage in database persistent storage

  • Xcode version: 9.0 (9A235)
  • Firebase SDK version: 4.2.0
  • Library version: 4.2.0
  • Firebase Product: database

Hello, we store dates in firebase like long numbers in milliseconds since the epoch. All works fine, until I enable database data persistence on disk

It looks like, SDK stores long values as ints and int overflow happens.

When I download value like 1506428988000 from database - all works fine, but, when I fetch same value from local cache - it returns -1104532896

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Guys, any progress on this issue?

The fix has landed! I’ll make a comment when it’s shipped (unfortunately the next release has already been assembled so it’ll have to make it into the next one after that, ~2 weeks from now).

I’ve contacted Firebase support about this and they asked for a way to reproduce the issue. I thought I may as well post it here as well.

func runOnFirstOpen() {
    Database.database().isPersistenceEnabled = true
    let ref = Database.database().reference(withPath: "start")
    ref.setValue(1506428988000)
}

// Now force close the app, turn on airplane mode, and open the app

func runOnSecondOpen() {
    Database.database().isPersistenceEnabled = true
    let ref = Database.database().reference(withPath: "start")
    ref.observe(.value) { (snapshot) in
        let start = snapshot.value as? Int64

        // "start" should be 1506428988000 but it is -1104532896

        // If you now turn off airplane mode another value event is received
        // with the correct value of 1506428988000
    }
}

Edit: Replaced “keepSynced” with “setPersistenceEnabled” to correctly repro the issue.