OutOfMemoryError: unable to create new native thread #786
Copy link
Copy link
Open
Labels
Description
In our project, there is a large number of OOM issues @nkzawa @darrachequesne . relate oom issue
and the errors all point to the EventThread class.
The root cause is that the single-thread pool in the EventThread class closes every time after completing a task, and a new thread pool needs to be created again when executing tasks next time.
Is this code reasonable? It seems that the purpose of the thread pool has been lost, as threads are not being reused and are instead being constantly recreated, leading to the OOM problem.
Is there any special logic here? What issues might arise if we remove the logic that closes the thread pool?
Reactions are currently unavailable
Activity
[-]OutOfMemoryError: unable toc reate new native thread[/-][+]OutOfMemoryError: unable to create new native thread[/+]ajayjapan commentedon Jul 11, 2026
Hi @nkzawa @darrachequesne, thanks for maintaining this library.
I may be wrong about this, but wanted to share some crash traces in case they're useful. I'm on
engine.io-client 2.1.0/socket.io-client 2.1.2and hitting what looks like the same class of issue described here.I'm seeing two distinct
OutOfMemoryError: pthread_createsignatures:Crash 1 - EventThread running reconnect, Timer creation fails:
Crash 2 - Timer fires, EventThread has no live worker:
My hypothesis (and I could definitely be missing something) is that the
counter/shutdownpattern inEventThread.nextTickcauses the executor to shut down and null out whenever it goes idle. The next reconnect attempt creates a newTimer(new OS thread) whose callback callsnextTick, findsservice == null, and spins up a freshnewSingleThreadExecutor(another new OS thread). Under memory pressure on mobile this exhausts the process thread limit.Happy to provide any additional context if it helps. Thanks!