Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 41 by [email protected]: TCPTransportClient.sendMessage() does not
write all bytes when the pipe is full, and the rest of the message is
discarded
http://code.google.com/p/jdiameter/issues/detail?id=41
In sendMessage(),
rc = socketChannel.write(bytes);
the code assumes that all the bytes have been written out. However, if the
socket is not available for writing, only a portion of the bytes (or none
at all) will in fact be written, since socketChannel is non blocking
channel.
This can occur when the other side not reading/processing messages fast
enough and the TCP send window becomes full. This is the circumstance under
which I encountered this issue. Messages that I was sending were not being
fully sent. A simple fix such as :
rc = 0;
while(rc<bytes.array().length)rc+= socketChannel.write(bytes);
resolved the issue.
For reference, here is the sendMessage() method :
--------------------------
public void sendMessage(ByteBuffer bytes) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("About to send a byte buffer of size [{}] over the TCP
nio socket [{}]", bytes.array().length, socketDescription);
}
int rc;
lock.lock();
try {
rc = socketChannel.write(bytes);
}
catch (Exception e) {
logger.debug("Unable to send message", e);
throw new IOException("Error while sending message: " + e);
}
finally {
lock.unlock();
}
if (rc == -1) {
throw new IOException("Connection closed");
}
if (logger.isDebugEnabled()) {
logger.debug("Sent a byte buffer of size [{}] over the TCP nio socket
[{}]", bytes.array().length, socketDescription);
}
}
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
---
You received this message because you are subscribed to the Google Groups "mobicents-all-issues-changes" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.