-
Notifications
You must be signed in to change notification settings - Fork 171
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
Improper creation of OkHttpClient in Websocket.java probably causing Out Of Memory exceptions #81
Comments
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. |
@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 #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 square/okhttp#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:
The text was updated successfully, but these errors were encountered: