|
From: Alexander G. <ago...@ac...> - 2007-05-23 14:35:13
|
Hello all! I am using the quickfix/j 1.1.0 to communicate with the FIX counterparty = using the SSL connection. And the application periodically freezes which = makes it impossible to use it in the production. I investigated the code = and the problem lies in the implementation of the code synchronization = for the org.apache.mina.filter.SSLFilter and the quickfix.Session. The = code in these classes is synchronised by the current SSLHandler instance = and the current Session instance respectively. And since the filter = chain goes from one filter to another without releasing the lock, there = is a high probability for an application to run into a deadlock.=20 That's what happened with my application. Below are the stack traces of = the reading and the writing threads that caused the deadlock with my = comments: // 1. The reading thread:=20 quickfix.Session.getDataDictionary(Session.java:1649) <--- attempt to = acquire the Session lock which is held by the writing thread [deadlock] quickfix.mina.AbstractIoHandler.messageReceived(AbstractIoHandler.java:11= 1) org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageRe= ceived(AbstractIoFilterChain.java:705) org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageRecei= ved(AbstractIoFilterChain.java:362) org.apache.mina.common.support.AbstractIoFilterChain.access$5(AbstractIoF= ilterChain.java:356) org.apache.mina.common.support.AbstractIoFilterChain$1.messageReceived(Ab= stractIoFilterChain.java:802) org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(Si= mpleProtocolDecoderOutput.java:60) org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(Protocol= CodecFilter.java:184) org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageRecei= ved(AbstractIoFilterChain.java:362) org.apache.mina.common.support.AbstractIoFilterChain.access$5(AbstractIoF= ilterChain.java:356) org.apache.mina.common.support.AbstractIoFilterChain$1.messageReceived(Ab= stractIoFilterChain.java:802) org.apache.mina.filter.SSLFilter.handleAppDataRead(SSLFilter.java:627) org.apache.mina.filter.SSLFilter.handleSSLData(SSLFilter.java:605) org.apache.mina.filter.SSLFilter.messageReceived(SSLFilter.java:395) = <--- acquisition of the SSLHandler lock ... // 2. The writing thread: org.apache.mina.filter.SSLFilter.filterWrite(SSLFilter.java:456) <--- = attempt to acquire the SSLHandler lock which is held by the reading = thread [deadlock] org.apache.mina.common.support.AbstractIoFilterChain.callPreviousFilterWr= ite(AbstractIoFilterChain.java:447) org.apache.mina.common.support.AbstractIoFilterChain.access$8(AbstractIoF= ilterChain.java:440) org.apache.mina.common.support.AbstractIoFilterChain$1.filterWrite(Abstra= ctIoFilterChain.java:826) org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolEncoderOutputImp= l.doFlush(ProtocolCodecFilter.java:403) org.apache.mina.filter.codec.support.SimpleProtocolEncoderOutput.flush(Si= mpleProtocolEncoderOutput.java:110) org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCode= cFilter.java:220) org.apache.mina.common.support.AbstractIoFilterChain.callPreviousFilterWr= ite(AbstractIoFilterChain.java:447) org.apache.mina.common.support.AbstractIoFilterChain.access$8(AbstractIoF= ilterChain.java:440) org.apache.mina.common.support.AbstractIoFilterChain$1.filterWrite(Abstra= ctIoFilterChain.java:826) org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.filterWri= te(AbstractIoFilterChain.java:729) org.apache.mina.common.support.AbstractIoFilterChain.callPreviousFilterWr= ite(AbstractIoFilterChain.java:447) org.apache.mina.common.support.AbstractIoFilterChain.fireFilterWrite(Abst= ractIoFilterChain.java:437) org.apache.mina.transport.socket.nio.SocketSessionImpl.write0(SocketSessi= onImpl.java:191) org.apache.mina.common.support.BaseIoSession.write(BaseIoSession.java:145= ) org.apache.mina.common.support.BaseIoSession.write(BaseIoSession.java:131= ) quickfix.mina.IoSessionResponder.send(IoSessionResponder.java:38) quickfix.Session.send(Session.java:1627) quickfix.Session.sendRaw(Session.java:1576) <--- acquisition of the = Session lock ... As far as I can see, there is a high probability of having similar = deadlocks in other parts of the filter chain when using the SSLFilter. = The problem can be solved by changing the synchronization model for the = quickfix.Session class. I understand though that this task is rather = complex and time consuming. Do you see other ways of solving this? = Please advise, I am willing to contribute if necessary. Thank you, Alexander Gorbachev. |