within the "for ( ;; )" loop if the channel write fails to send, indicated by 0 being returned, the message is re-enqueued. However the loop is not exited and the same message is tried again. For each failure to send the same message over and over a new WriteRequest is added to the queue and the message will be sent again for each WriteRequest.
Even though the WriteRequest references the same IoBuffer, after each successful write the IoBuffer is reset which enables each subsequent WriteRequest in the queue to send it again.
I have had instances where the kernel buffer is full and delays for up to 500ms or so which resulted in ~ 300 duplicate messages being sent.
Here is the block of code in question within the for ( ;; ) loop:
- adding a "break;" after the message has been re-queued would certainly resolve this but then messages could be delivered out of order.
- don't re-queue the message and just loop back through trying to send it again.
- ensure that the SO_SNDBUF size is sufficiently large which could, depending on the application, alleviate the issue altogether or make it less likely to occur.