Skip to content

Error in streamingSync: Connect timeout has expired (Android App) #271

@miggiman

Description

@miggiman

When having ktor implemented in the app. PowerSync won't sync as it gets a timeout error thrown.
Tried with ktor version 3.3.0 and 3.2.3 (which is the same version as used in the library)

15:53:53.680 PowerSync             E  Error in streamingSync: Software caused connection abort
15:53:58.791 PowerSync             E  Error in streamingSync: Unable to resolve host "your domain": No address associated with hostname

When I removed

// Network
    implementation(libs.ktor.client.android)
    implementation(libs.ktor.client.content.negotiation)
    implementation(libs.ktor.client.logging)
    implementation(libs.ktor.serialization.kotlinx.json)

from build.gradle.kts

And used a OkHttpClient in PowerSyncBackendConnector everything works fine.

Example PowerSyncBackendConnector, same code fails with ktor implementation in gradle files. It doesn't even have to be in use:

class PSConnector() : PowerSyncBackendConnector() {

    private val httpClient = OkHttpClient()

    override suspend fun fetchCredentials(): PowerSyncCredentials? {
        val baseUrl = "base url";

        return try {
            val requestBody = "{}".toRequestBody("application/json".toMediaType())
            val request = Request.Builder()
                .url("${baseUrl}/api/powersync/auth") //Our custom auth endpoint
                .post(requestBody)
                .build()

            httpClient.newCall(request).execute().use { response ->
                if (!response.isSuccessful) {
                    return null
                }

                val responseBody = response.body?.string() ?: return null
                val jsonObject = JSONObject(responseBody)
                val token = jsonObject.getString("token")

                PowerSyncCredentials(
                    endpoint = "${baseUrl}/sync", //sync is necessary for our be setup. Thats not the problem ;)
                    token = token
                )
            }
        } catch (e: Exception) {
            null
        }
    }

    override suspend fun uploadData(database: PowerSyncDatabase) {
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions