Description
I found an issue on 2.1.x branch when a client is sending messages asynchronously.
I create a simple client and a server with a simple ObjectSerializationCodecFactory.
On a client, I send simple String messages (e.g. Message:1) inside a thread pool (size=2).
Then I check:
- On client, I check that I send all these messages and avoid duplicate.
- On server, I check that I receive all these messages.
If client send "1000" messages on thread pool with 2 threads, server will miss 11messages:
12:24:59,573 INFO <main> missingMessageTest.begin with 1000 messages and 2 threads 12:24:59,577 INFO <main> missingMessageTest.end 12:24:59,577 INFO <main> missingMessageTest.sleep... 1000 12:24:59,580 ERROR <NioProcessor-14> messageSent: message <Message:21> already sent 12:24:59,581 ERROR <NioProcessor-14> messageSent: message <Message:27> already sent 12:24:59,584 ERROR <NioProcessor-14> messageSent: message <Message:113> already sent 12:24:59,587 ERROR <NioProcessor-14> messageSent: message <Message:164> already sent 12:24:59,592 ERROR <NioProcessor-14> messageSent: message <Message:313> already sent 12:24:59,596 ERROR <NioProcessor-14> messageSent: message <Message:386> already sent 12:24:59,604 ERROR <NioProcessor-14> messageSent: message <Message:567> already sent 12:24:59,605 ERROR <NioProcessor-14> messageSent: message <Message:615> already sent 12:24:59,606 ERROR <NioProcessor-14> messageSent: message <Message:628> already sent 12:24:59,611 ERROR <NioProcessor-14> messageSent: message <Message:760> already sent 12:24:59,612 ERROR <NioProcessor-14> messageSent: message <Message:822> already sent 12:25:00,578 INFO <main> missingMessageTest.sleep... 2000 12:25:01,578 INFO <main> missingMessageTest.sleep... 3000 12:25:02,579 INFO <main> missingMessageTest.sleep... 4000 12:25:03,579 INFO <main> missingMessageTest.sleep... 5000 12:25:04,579 INFO <main> missingMessageTest.close 12:25:04,582 ERROR <main> missing <11> messages : [Message:760, Message:27, Message:21, Message:313, Message:567, Message:822, Message:615, Message:628, Message:386, Message:113, Message:164]
I works fine with one thread (e.g. synchronous send).
This junit works with "Apache Mina" "2.0.21", it failed with "2.1.x" branch.
I attach my junit to reproduce this issue on your side.
Attachments
Attachments
Issue Links
- is duplicated by
-
DIRMINA-845 ProtocolEncoderOutputImpl isn't thread-safe
- Resolved
-
DIRMINA-1145 Mina Server is losing messages
- Resolved
I want to note that AFAIK the ProtocolCodec package is not necessarily intended to be thread-safe. While it does use some concurrent structures like ConcurrentLinkedDeque, it also uses session specific encoder/decoder instances as well as ProtocolDeocderOutput.
I could delegate the retrieval of the ProtocolEncoderOutput to the ProtocolCodecFactory. This would put the thread-safe "ness" more in the hands of the specific implementation and not the framework.
elecharny what you do think about the suggested API change? Adding the default method to the abstract class should prevent it from breaking backwards compatibility.