From b9101b033194c727bc7e8dbe15d7eb98baecd458 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 26 Aug 2014 15:07:02 +0200 Subject: [PATCH] [#2823] Writing DefaultFileRegion with EpollSocketChannel may cause hang Motivation: In EpollSocketchannel.doWriteFileRegion(...) we need to make sure we write until sendFile(...) returns either 0 or all is written. Otherwise we may not get notified once the Channel is writable again. This is the case as we use EPOLL_ET. Modifications: Always write until either sendFile returns 0 or all is written. Result: No more hangs when writing DefaultFileRegion can happen. --- .../main/java/io/netty/channel/epoll/EpollSocketChannel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java index 12fb680bfe..d38bef175e 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java @@ -276,7 +276,7 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So boolean done = false; long flushedAmount = 0; - for (int i = config().getWriteSpinCount() - 1; i >= 0; i --) { + for (;;) { final long offset = region.transfered(); final long localFlushedAmount = Native.sendfile(fd, region, baseOffset, offset, regionCount - offset); if (localFlushedAmount == 0) {