You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have added the dependency as "compile 'io.socket:socket.io-client:0.7.0' ". I created the last build on 25-05-2016. Could you please fix this memory issue.
Android 4.4.2
Model : GT-I9301I
Crash report:
Crashed Thread
0 java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
1 at java.lang.VMThread.create(Native Method)
2 at java.lang.Thread.start(Thread.java:1029)
3 at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
4 at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1327)
5 at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:583)!
6 at io.socket.thread.EventThread.nextTick(SourceFile:71)
7 at io.socket.thread.EventThread.exec(SourceFile:52)
8 at io.socket.engineio.client.transports.PollingXHR$6.call(SourceFile:122)
9 at io.socket.emitter.Emitter.emit(SourceFile:117)
10 at io.socket.engineio.client.transports.PollingXHR$Request.onError(SourceFile:251)
11 at io.socket.engineio.client.transports.PollingXHR$Request.access$700(SourceFile:135)
12 at io.socket.engineio.client.transports.PollingXHR$Request$1.run(SourceFile:218)
13 at java.lang.Thread.run(Thread.java:841)
Reacted by Shobhit Puri, Pham Le Tan Dat, Hayk, Ground, SeyyedMojtaba Akramazde and Abhay Koradiya
Hi Shobhitpuri, I didn't get any solution for this issue. Also, I am unable to reproduce this issue in my available phones :(. I will try to simulate this issue and update you if I get any solution.
Fatal Exception: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:1063) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1328) at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:584) at io.socket.thread.EventThread.nextTick(EventThread.java:76) at io.socket.thread.EventThread.exec(EventThread.java:57) at io.socket.engineio.client.transports.WebSocket$2.onFailure(WebSocket.java:147) at okhttp3.ws.WebSocketCall$1.onFailure(WebSocketCall.java:104) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
What can be a clue is that when app crashed there was more than 2000 threads and almost all of them looked like this
OkHttp ConnectionPool at java.lang.Object.wait(Object.java) at okhttp3.ConnectionPool$1.run(ConnectionPool.java:66) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
Hi @alexvimodev, @mgwizdala Is there any update on this issue ?
because i am getting the same problem in my app
Fatal Exception: java.lang.OutOfMemoryError: Could not allocate JNI Env at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:1063) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1328) at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:584) at io.socket.thread.EventThread.nextTick(EventThread.java:71) at io.socket.thread.EventThread.exec(EventThread.java:52) at io.socket.engineio.client.transports.WebSocket$1.onMessage(WebSocket.java:104) at okhttp3.internal.ws.RealWebSocket$1.onMessage(RealWebSocket.java:62) at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:242) at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:108) at okhttp3.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:97) at okhttp3.ws.WebSocketCall.createWebSocket(WebSocketCall.java:152) at okhttp3.ws.WebSocketCall.access$000(WebSocketCall.java:41) at okhttp3.ws.WebSocketCall$1.onResponse(WebSocketCall.java:97) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
@mgwizdala@alexvimodev@KrawczykPawel Check lysine-dev/okhttp#2846 . I see similar behaviour in stack traces, where I see more than 1000 to 2000 threads. I am trying to distinguish if the issue is with the library or my app. I am using Retrofit and OkHttpClient.Builder for performing Rest request. Maybe my Singleton implementation is not correct because of which so many threads are being created. Are you using Retrofit too in your project by any chance?
Unfortunately project that i am working on is configured to use Volley for
normal http requests. Okhttp is used only by SocketIO so this bug must be
related with one of this two libraries.
2017-01-23 21:31 GMT+01:00 Shobhit Puri <notifications@github.com>:
@shobhitpuri@mgwizdala, I am using only socketio library in my project. Thats why I created the issue in github with this project. But, I am not getting this crash in "socket.io-client-0.8.3" (till now).
OkHttp performs best when you create a single OkHttpClient instance and reuse it for all of your HTTP calls. This is because each client holds its own connection pool and thread pools. Reusing connections and threads reduces latency and saves memory. Conversely, creating a client for each request wastes resources on idle pools.
Use new OkHttpClient() to create a shared instance with the default settings:
// The singleton HTTP client.
public final OkHttpClient client = new OkHttpClient();
Or use new OkHttpClient.Builder() to create a shared instance with custom settings:
// The singleton HTTP client.
public final OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor())
.cache(new Cache(cacheDir, cacheSize))
.build();
However if you see line 42 the Websocket.java file in the engine.io project (which is used by socket.io-client-java), we are creating a new instance of OkHttpClient each time doOpen() is called. So if in your app you close and open connection multiple times, then each time new instance of the client will be created and will hold its own set of connection pools. This might be what is leading to the OOM exceptions.
@alexvimodev Thanks for the update. I hope the crash doesn't happen anymore with 0.8.3. I will try updating. However I've opened an issue with socketio/engine.io-client-java#81. Please do update here in case you see crashes happening on socket.io-client-0.8.3 as well. Thanks so much!
It keeps crashing a lot (v0.8.3) :( even using the created socket do send a presence flag... it is possible that only one socket could exists? In my app I've launched 2 different sockets for different functionalities
@iflorit I am using more than one socket connection in my app. It is working fine with v.0.8.3 without this memory issue. There could be different issue in your case.
I'm using this library as well in my app using v0.8.3, and I'm experiencing this OOM issue but on my investigation, the problem was being encountered when my app keep creating new socket instance due to wrong singleton socket constructor.
Activity
shobhitpuri commentedon Jul 7, 2016
+1 . It is happening to lot of my users as well.
shobhitpuri commentedon Aug 2, 2016
Any updates on this? @alexvimodev Were you able to figure out a solution? Thanks.
alexvimodev commentedon Aug 5, 2016
Hi Shobhitpuri, I didn't get any solution for this issue. Also, I am unable to reproduce this issue in my available phones :(. I will try to simulate this issue and update you if I get any solution.
Thank you.
KrawczykPawel commentedon Aug 5, 2016
I have the same issue on various Android phones (Galaxy Nexus 6, Samsung S4) OS version 5.1, 6:
mgwizdala commentedon Nov 7, 2016
I have similiar issue in my app
Fatal Exception: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:1063) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1328) at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:584) at io.socket.thread.EventThread.nextTick(EventThread.java:76) at io.socket.thread.EventThread.exec(EventThread.java:57) at io.socket.engineio.client.transports.WebSocket$2.onFailure(WebSocket.java:147) at okhttp3.ws.WebSocketCall$1.onFailure(WebSocketCall.java:104) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)What can be a clue is that when app crashed there was more than 2000 threads and almost all of them looked like this
OkHttp ConnectionPool at java.lang.Object.wait(Object.java) at okhttp3.ConnectionPool$1.run(ConnectionPool.java:66) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)Mukesh-Singh commentedon Dec 14, 2016
Hi @alexvimodev, @mgwizdala Is there any update on this issue ?
because i am getting the same problem in my app
Fatal Exception: java.lang.OutOfMemoryError: Could not allocate JNI Env at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:1063) at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1328) at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:584) at io.socket.thread.EventThread.nextTick(EventThread.java:71) at io.socket.thread.EventThread.exec(EventThread.java:52) at io.socket.engineio.client.transports.WebSocket$1.onMessage(WebSocket.java:104) at okhttp3.internal.ws.RealWebSocket$1.onMessage(RealWebSocket.java:62) at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:242) at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:108) at okhttp3.internal.ws.RealWebSocket.readMessage(RealWebSocket.java:97) at okhttp3.ws.WebSocketCall.createWebSocket(WebSocketCall.java:152) at okhttp3.ws.WebSocketCall.access$000(WebSocketCall.java:41) at okhttp3.ws.WebSocketCall$1.onResponse(WebSocketCall.java:97) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)unable to figure out the reason and any solution.
shobhitpuri commentedon Jan 23, 2017
@mgwizdala @alexvimodev @KrawczykPawel Check lysine-dev/okhttp#2846 . I see similar behaviour in stack traces, where I see more than 1000 to 2000 threads. I am trying to distinguish if the issue is with the library or my app. I am using Retrofit and
OkHttpClient.Builderfor performing Rest request. Maybe my Singleton implementation is not correct because of which so many threads are being created. Are you using Retrofit too in your project by any chance?mgwizdala commentedon Jan 23, 2017
alexvimodev commentedon Jan 24, 2017
@shobhitpuri @mgwizdala, I am using only socketio library in my project. Thats why I created the issue in github with this project. But, I am not getting this crash in "socket.io-client-0.8.3" (till now).
shobhitpuri commentedon Jan 24, 2017
@mgwizdala You might be right. It seems to be the engie.io project.
@alexvimodev Not sure how much of that is fixed. It might be just a matter of time. If you read https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html and lysine-dev/okhttp#2846, it says
However if you see line 42 the Websocket.java file in the engine.io project (which is used by
socket.io-client-java), we are creating a new instance of OkHttpClient each timedoOpen()is called. So if in your app you close and open connection multiple times, then each time new instance of the client will be created and will hold its own set of connection pools. This might be what is leading to the OOM exceptions.shobhitpuri commentedon Jan 30, 2017
@alexvimodev Thanks for the update. I hope the crash doesn't happen anymore with
0.8.3. I will try updating. However I've opened an issue with socketio/engine.io-client-java#81. Please do update here in case you see crashes happening onsocket.io-client-0.8.3as well. Thanks so much!iflorit commentedon Mar 20, 2017
It keeps crashing a lot (v0.8.3) :( even using the created socket do send a presence flag... it is possible that only one socket could exists? In my app I've launched 2 different sockets for different functionalities
alexvimodev commentedon Mar 20, 2017
@iflorit I am using more than one socket connection in my app. It is working fine with v.0.8.3 without this memory issue. There could be different issue in your case.
JayCM commentedon Apr 28, 2017
Hi All,
I'm using this library as well in my app using v0.8.3, and I'm experiencing this OOM issue but on my investigation, the problem was being encountered when my app keep creating new socket instance due to wrong singleton socket constructor.
darrachequesne commentedon Jun 29, 2022
For future readers:
This should be fixed in latest versions.
Related: socketio/engine.io-client-java#81
Please reopen if needed.