Skip to content

Commit f156123

Browse files
committed
Only set EAGAIN when written == 0 and length > 0. Fixes #2957
Because we use NIO channels for all IO, but need to behave like POSIX IO functions, we emulate errno behavior for various cases. This particular issue is an edge case, when writing zero bytes to a stream marked as nonblocking (as happens after it is used in an IO.select operation); we see that it's nonblocking and nothing was written and unconditionally treat that as EAGAIN. Instead, we should only set EAGAIN when zero bytes are written and we actually did have bytes to write.
1 parent ae31756 commit f156123

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/src/main/java/org/jruby/util/io/PosixShim.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public int write(ChannelFD fd, byte[] bytes, int offset, int length, boolean non
9191

9292
int written = fd.chWrite.write(tmp);
9393

94-
if (written == 0) {
94+
if (written == 0 && length > 0) {
9595
// if it's a nonblocking write against a file and we've hit EOF, do EAGAIN
9696
if (nonblock) {
9797
errno = Errno.EAGAIN;

0 commit comments

Comments
 (0)