mirror of
https://github.com/etesync/android
synced 2024-11-14 03:39:52 +00:00
Add a lock when pushing changes.
This is not needed for proper deployments where the server properly locks the database tables. But in some older etesync server versions and possibly bad databases, this is not the case. OpenTasks causes EteSync to concurrently try to sync, so this at least makes sure this race condition doesn't happen for these rare cases.
This commit is contained in:
parent
e83c95e8ec
commit
63cbaddfc6
@ -33,8 +33,10 @@ import java.io.Closeable
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import java.util.logging.Level
|
||||
import javax.net.ssl.SSLHandshakeException
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
abstract class SyncManager<T: LocalResource<*>> @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class)
|
||||
constructor(protected val context: Context, protected val account: Account, protected val settings: AccountSettings, protected val extras: Bundle, protected val authority: String, protected val syncResult: SyncResult, journalUid: String, protected val serviceType: CollectionInfo.Type, accountName: String): Closeable {
|
||||
@ -393,8 +395,11 @@ constructor(protected val context: Context, protected val account: Account, prot
|
||||
// FIXME: Deal with failure (someone else uploaded before we go here)
|
||||
try {
|
||||
if (!localEntries!!.isEmpty()) {
|
||||
val entries = localEntries
|
||||
journal!!.create(entries!!, remoteCTag)
|
||||
val entries = localEntries!!
|
||||
pushLock.withLock {
|
||||
journal!!.create(entries, remoteCTag)
|
||||
}
|
||||
|
||||
// Persist the entries after they've been pushed
|
||||
for (entry in entries) {
|
||||
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
||||
@ -577,5 +582,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
||||
companion object {
|
||||
private val MAX_FETCH = 50
|
||||
private val MAX_PUSH = 30
|
||||
|
||||
private val pushLock = ReentrantLock()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user