Skip to content

WebSocket not retrying connection when server closes connection #80

Open
@martinmihalic

Description

I'm dealing with a problem that my server could be unstable at the time and he could silently reboot itself. The issue is that my socket is not retrying connection after the server closes it. Is that expected behaviour? These are the logs that I get:

2019-06-26 00:43:28.715 32195-32420/(ConnectionManagerImpl.kt:40)#onServerReadyChange DebugTree: Dispatching web socket connection event > OnConnectionClosing(shutdownReason=ShutdownReason(code=1001, reason=The web application is stopping))

2019-06-26 00:43:28.728 32195-32420/(ConnectionManagerImpl.kt:40)#onServerReadyChange DebugTree: Dispatching web socket connection event > OnConnectionClosed(shutdownReason=ShutdownReason(code=1001, reason=The web application is stopping))

My implementation of Scarlet configuration is this:

inline fun <reified T> createWebSocketService(okHttpClient: OkHttpClient, url: String, objectMapper: ObjectMapper, application: Application): T {
    val protocol = OkHttpWebSocket(
            okHttpClient,
            OkHttpWebSocket.SimpleRequestFactory(
                    { Request.Builder().url(url).build() },
                    { ShutdownReason.GRACEFUL }
            )
    )
    val configuration = Scarlet.Configuration(
            messageAdapterFactories = listOf(JacksonMessageAdapter.Factory(objectMapper)),
            streamAdapterFactories = listOf(RxJava2StreamAdapterFactory()),
            backoffStrategy = LinearBackoffStrategy(5000),
            lifecycle = AndroidLifecycle.ofApplicationForeground(application)
    )
    return Scarlet(protocol, configuration).create(T::class.java)
}

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