socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.31k stars 969 forks source link

io.socket.client.IO::managers leaks resources #742

Open valeriyo opened 1 year ago

valeriyo commented 1 year ago

Describe the bug The IO::managers map is added to, but never removed from, and there is no method to clear it - so a bunch of stuff leaks.

To Reproduce

Use LeakCanary to watch OkHttpClient instances passed into IO::Options.callFactory / webSocketFactory - after IO.socket.close() - those OkHttpClient will leak, being held by IO::managers - which is added to, but is never cleared.

Socket.IO java client version: 2.1.0

Expected behavior Either automatically remove entries from IO::managers when sockets are closed, or provide a method to clear IO::managers map - and release the resources held by it.

Platform:

valeriyo commented 1 year ago

BTW, the workaround is:

    IO::class.java.declaredFields.first { it.name == "managers" }.apply {
      isAccessible = true
      val managers = get(null) as ConcurrentHashMap<*, *>
      managers.clear()
    }

and then in proguard-rules.pro:

-keepclassmembers class io.socket.client.IO {
    private static final ** managers;
}