F-Droid version: ensure timeout of sync request can be more than 60 seconds (#2169)

This commit is contained in:
Benoit Marty 2020-11-13 19:14:50 +01:00
parent 8dff0b2c5d
commit 64c612dea0
4 changed files with 23 additions and 6 deletions

View file

@ -9,6 +9,7 @@ Improvements 🙌:
- Handle events of type "m.room.server_acl" (#890)
Bugfix 🐛:
- F-Droid version: ensure timeout of sync request can be more than 60 seconds (#2169)
- Fix issue when restoring draft after sharing (#2287)
- Fix issue when updating the avatar of a room (new avatar vanishing)
- Discard change dialog displayed by mistake when avatar has been updated

View file

@ -52,5 +52,8 @@ internal class TimeOutInterceptor @Inject constructor() : Interceptor {
const val CONNECT_TIMEOUT = "CONNECT_TIMEOUT"
const val READ_TIMEOUT = "READ_TIMEOUT"
const val WRITE_TIMEOUT = "WRITE_TIMEOUT"
// 1 minute
const val DEFAULT_LONG_TIMEOUT: Long = 60_000
}
}

View file

@ -17,18 +17,21 @@
package org.matrix.android.sdk.internal.session.sync
import org.matrix.android.sdk.internal.network.NetworkConstants
import org.matrix.android.sdk.internal.network.TimeOutInterceptor
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Header
import retrofit2.http.QueryMap
internal interface SyncAPI {
/**
* Set all the timeouts to 1 minute
* Set all the timeouts to 1 minute by default
*/
@Headers("CONNECT_TIMEOUT:60000", "READ_TIMEOUT:60000", "WRITE_TIMEOUT:60000")
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "sync")
fun sync(@QueryMap params: Map<String, String>): Call<SyncResponse>
fun sync(@QueryMap params: Map<String, String>,
@Header(TimeOutInterceptor.CONNECT_TIMEOUT) connectTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT,
@Header(TimeOutInterceptor.READ_TIMEOUT) readTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT,
@Header(TimeOutInterceptor.WRITE_TIMEOUT) writeTimeOut: Long = TimeOutInterceptor.DEFAULT_LONG_TIMEOUT
): Call<SyncResponse>
}

View file

@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.session.sync
import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.R
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.network.TimeOutInterceptor
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.DefaultInitialSyncProgressService
import org.matrix.android.sdk.internal.session.filter.FilterRepository
@ -78,8 +79,13 @@ internal class DefaultSyncTask @Inject constructor(
// Maybe refresh the home server capabilities data we know
getHomeServerCapabilitiesTask.execute(Unit)
val readTimeOut = (params.timeout + TIMEOUT_MARGIN).coerceAtLeast(TimeOutInterceptor.DEFAULT_LONG_TIMEOUT)
val syncResponse = executeRequest<SyncResponse>(eventBus) {
apiCall = syncAPI.sync(requestParams)
apiCall = syncAPI.sync(
params = requestParams,
readTimeOut = readTimeOut
)
}
syncResponseHandler.handleResponse(syncResponse, token)
if (isInitialSync) {
@ -87,4 +93,8 @@ internal class DefaultSyncTask @Inject constructor(
}
Timber.v("Sync task finished on Thread: ${Thread.currentThread().name}")
}
companion object {
private const val TIMEOUT_MARGIN: Long = 10_000
}
}