OpenSmpp / opensmpp

OpenSmpp - Java library implementing the SMPP protocol, and allowing development of External Short Message Entities (ESMEs) and more.
http://opensmpp.org/
Other
188 stars 170 forks source link

Thread.yield causes high CPU load in ProcessingThread start/stop #11

Closed paoloc0 closed 8 years ago

paoloc0 commented 8 years ago

Using the original Logica SMPP (precursor to OpenSMPP) code in an SMPP server implementation, it was observed that some threads would occasionally cause 100% CPU load for a 60 second period, when a particular SMPP client tried to connect, but failed because the bind request was deemed invalid.

This particular client seemed to not shut down the TCP session timeously, which caused a race condition that could occasionally lead to Thread.yield() being run in a tight loop in ProcessingThread, waiting for TCP socket shutdown.

During periods of high CPU load, thread dumps showed threads that persisted in this state for ~60 seconds:

   java.lang.Thread.State: RUNNABLE
        at java.lang.Thread.yield(Native Method)
        at com.logica.smpp.util.ProcessingThread.stop(ProcessingThread.java:165)
        at com.logica.smpp.Receiver.stop(Receiver.java:234)
        at <some code that tries to stop() a Receiver>

The same code still exists in OpenSMPP, and should be fixed (Thread.yield replaced with Thread.sleep) here too.

Internal issue tracker ref: TP-6228.