[ https://issues.apache.org/jira/browse/DIRMINA-653?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13574412#comment-13574412 ]
Jens Reimann commented on DIRMINA-653: -------------------------------------- Well in my opinion this issue is still open. I stumbled right over it and the fix only solves one part of the problem. I would guess, but this is only a guess, that this would also affect the SslFilter. After some debugging I found out that when multiple threads call "session.write" at the same time, the filter chain is processes unsynchronized by default. This will make several parallel calls to "doFilterWrite" and also to "deflate" in the "Zlib" helper class. While the stream is synchronized, the stream state is not synchronized with the underlying socket. The result of the "deflate" could contain a dictionary update if the zlib stream. If the following parallel call uses this new dictionary it needs to be written to the socket after the first call updated the dictionary. But this is not guaranteed! When the "deflate" method returns there is no lock on the filter chain anymore and the second packet may overtake the first packet (which holds the dictionary update). Hence the result on the other side will be a packet which is decoded with the wrong dictionary. It took my quite a while to figure that out since every test case I made was single threaded. So the assumption that IoSession is thread safe is simply wrong. I am not sure how to solve the issue here. I guess a simple mutex lock when writing to a session would do the trick in our case. In any way I would suggest to update the documentation to reflect that situation. > IoSession.write not thread-safe? Loosing messages under heavy multi-threaded > write on same session. > --------------------------------------------------------------------------------------------------- > > Key: DIRMINA-653 > URL: https://issues.apache.org/jira/browse/DIRMINA-653 > Project: MINA > Issue Type: Bug > Components: Core, Filter > Affects Versions: 2.0.0-M4 > Environment: Windows Vista 64-bit > Reporter: Mauritz Lovgren > Fix For: 2.0.0-M5 > > > I am writing a stress-test that tests multi-thread safetyness of our > stateless encoder / decoder under heavy load and I am observing that messages > are silently lost during session.write(Object), (the lost messages do not > seem to reach the underlying socket buffer at all). > I am using one encoder / decoder that is stateless. No executor filter, only > the filter codec and a basic io handler. > Synchronizing on the session.write makes the problem go away; > synchronized (session) > { > future = session.write(message); > } > Do I really have to synchronize on the session to solve this issue? -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira