diff --git a/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java
index <HASH>..<HASH> 100644
--- a/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java
+++ b/src/main/java/org/jboss/netty/buffer/AbstractChannelBuffer.java
@@ -427,7 +427,9 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
     public int writeBytes(ScatteringByteChannel in, int length)
             throws IOException {
         int writtenBytes = setBytes(writerIndex, in, length);
-        writerIndex += writtenBytes;
+        if (writtenBytes > 0) {
+            writerIndex += writtenBytes;
+        }
         return writtenBytes;
     }
Fixed a bug where AbstractChannelBuffer.writeBytes() decreases the writerIndex when the specified channel is closed.