Closed shobhitpuri closed 7 years ago
Maybe we should let develop inject their OkHttpClient so an application could use only one client instance.
I am having this issue, in the case of my Socket.IO server being offline and the java client trying to connect (or reconnect), creating new threads that don't close, forever. So I have attempted to make a fix in my own fork, which seems to be working for my application. With my changes, I am simply passing shareOkHttpClient as true to the socket options. Feel free to use the same changes for the fix. https://github.com/Unchosen/engine.io-client-java/commit/51d41d64e98581efb90a6d30ddefaa3063552914
@Unchosen That's great news! I see that you forked the original repo. Can you please make a pull request to the original repo as well?
@b95505017 Can you please look into the pull request https://github.com/socketio/engine.io-client-java/pull/82 by @Unchosen when you get time? Hopefully it solves this issue. Thanks so much.
@shobhitpuri Ok I'll review it ASAP.
The fix was released as 0.9.0, thanks to @b95505017. Let us know when the problem still happens.
Issue: I have been having issue with 100's of Out of Memory exceptions in my Android app which is using socket.io-client-java library since couple of months and I've been trying a lot to figure out. The library uses engine.io library.
Hypothesis: After doing some exploration, this is the hypothesis I have. Please feel free to suggest your thoughts or a fix. In Websocket.java file, each time
doOpen()
is being called, a new instance ofOkHttpClient
is being initialized as follows:Based on a comment by swankjesse at Square, on an issue opened on okhttp regarding the OOM exceptions, he suggested to share the instance of
OkHttpClient
. Otherwise each time when we are creating a new instance ofOkHttpClient
, it will hold its own connection pool and thread pool, which is what seems to be happening when callingdoOpen()
inWebsocket.java
. An app which closes connection and opens connection multiple times in its workflow is having lot of OOM exceptions (stacktrace same as on https://github.com/square/okhttp/issues/2846). When a mobile app goes in background, one would want to close connection to prevent using resources and then re-open connection when app is visible.From the okhttp docs:
Solution seems to be fixing it as mentioned in the docs. Feel free to comment if the hypothesis seems wrong.
Thanks
References: