fix race in TcpConnection. patch by Jun Rao; reviewed by jbellis for CASSANDRA-220

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/branches/cassandra-0.3@782656 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-06-08 14:44:57 +00:00
parent 0e43f5a073
commit 629b696491
1 changed files with 22 additions and 22 deletions

View File

@ -425,30 +425,30 @@ public class TcpConnection extends SelectionKeyHandler implements Comparable
void doPendingWrites()
{
try
{
while(!pendingWrites_.isEmpty())
{
ByteBuffer buffer = pendingWrites_.get(0);
socketChannel_.write(buffer);
if (buffer.remaining() > 0)
{
break;
}
pendingWrites_.remove(0);
}
}
catch(IOException ex)
synchronized(this)
{
logger_.warn(LogUtil.throwableToString(ex));
// This is to fix the wierd Linux bug with NIO.
errorClose();
}
finally
{
synchronized(this)
try
{
while(!pendingWrites_.isEmpty())
{
ByteBuffer buffer = pendingWrites_.get(0);
socketChannel_.write(buffer);
if (buffer.remaining() > 0)
{
break;
}
pendingWrites_.remove(0);
}
}
catch(IOException ex)
{
logger_.warn(LogUtil.throwableToString(ex));
// This is to fix the wierd Linux bug with NIO.
errorClose();
}
finally
{
if (!pendingWrites_.isEmpty())
{
key_.interestOps(key_.interestOps() | SelectionKey.OP_WRITE);