0

I have a for loop - running 6 times - containing an async function that uploads an object to a database. When called the function only uploads 3 - 4 objects and for the remaining 2 - 3 the console prints:

fServer reported an error: FAULT = 'Server.Processing' [java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction]

I've read other threads regarding this issue and I followed the advise to use dispatch groups. Unfortunately it's still not working for me and I do not understand why. How can I avoid these deadlocks from happening?

func uploadObjects() {

    let myGroup = dispatch_group_create()

    self.backendless.initApp(self.APP_ID, secret: self.SECRET_KEY, version: self.VERSION_NUM)

    for object in objects {

        dispatch_group_enter(myGroup)

        let dataStore = backendless.data.of(Game.ofClass())

        // save object asynchronously
        dataStore.save(
            game,
            response: { (result: AnyObject!) -> Void in

                dispatch_group_leave(myGroup)

                let obj = result as! Game

                print("Game saved: \(obj.objectId)")

            },
            error: { (fault: Fault!) -> Void in
                print("fServer reported an error: \(fault)")
        })

    }

    dispatch_group_notify(myGroup, dispatch_get_main_queue(), {

        print("Finished all requests.")

    })
}
Community
  • 1
  • 1
Stiño
  • 2,663
  • 7
  • 25
  • 47
  • looks like a server issue really... – Wain Jul 10 '16 at 14:02
  • you shouldn't fix server side problems in client side.It seems server side need to deal with threading problems. – Ali Kıran Jul 10 '16 at 14:07
  • This is definitely an issue on backend, not in your code. Could you please share this problem on support.backendless.com? We'll try to investigate your case. – Scadge Jul 11 '16 at 09:33

0 Answers0