Infinite loop of NullPointerExceptions in Socks5Proxy

Under certain conditions, the Socks5ServerProcess in smack-extensions (org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy$Socks5ServerProcess) falls into an endless loop of throwing and catching NullPointerExceptions, causing 100% CPU usage.

Thread dump from jstack:

“Thread-77” daemon prio=10 tid=0x00007ff7d8195800 nid=0x25d1 runnable [0x00007ff7bc1db000]

java.lang.Thread.State: RUNNABLE

at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Throwable.java:783)
- locked <0x00000000eaa2dd68> (a java.lang.NullPointerException)
at java.lang.Throwable.<init>(Throwable.java:250)
at java.lang.Exception.<init>(Exception.java:54)
at java.lang.RuntimeException.<init>(RuntimeException.java:51)
at java.lang.NullPointerException.<init>(NullPointerException.java:60)
at org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy$Socks5ServerProcess.run( Socks5Proxy.java:367)
at java.lang.Thread.run(Thread.java:745)

The exit condition in Socks5ServerProcess#run() should test whether Socks5Proxy.this.serverSocket is null before testing Socks5Proxy.this.serverSocket.isClosed(). The serverSocket can be null if this.serverThread.join() was interrupted in Socks5Proxy#stop().

Found in version 4.0.7.

Thanks for reporting. Tracked as SMACK-707.

I’ve pushed Smack 4.1.6-SNAPSHOT to Maven Central’s snapshot repositories, which includes Check for ‘null’ to avoid NPE in Socks5Proxy · Flowdalic/Smack@f34f37a · GitHub . Could you try and report back if it fixes the issue for you?

Hi,

Thanks for the quick fix. Your commit fixes the issue.