Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket not retrying connection when server closes connection #80

Open
martinmihalic opened this issue Jun 25, 2019 · 4 comments
Open

Comments

@martinmihalic
Copy link

martinmihalic commented Jun 25, 2019

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)
}
@muhammadFawzy
Copy link

any updates about this?

@axelbau24
Copy link

Figured out that this might be an issue with older versions of Android, i am working on an app that uses Android 4.4 the websocket doesn't reconnect, but in newer versions it works fine, not sure how to go about this.

@muhammadFawzy
Copy link

@axelbau24 i don't think it's related to android version as i have android 8 and 9 and when server is down for 1 minute for any reason websocket doesn't trying to reconnect.

@TTransmit
Copy link

Could this issue have the same underlying cause as #65, which is retrying being stopped by a WebSocket.Event.OnConnectionFailed event? There is a fix proposed in #66 that could be good to try.

I've been listening for these events and closing and reopening a Scarlet LifecycleRegistry instance to work around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants