RFR: 8274548: (fc) FileChannel gathering write fails with IOException "Invalid argument" on macOS 11.6

Brian Burkhalter bpb at openjdk.java.net
Wed Oct 6 00:08:25 UTC 2021


On Wed, 6 Oct 2021 00:00:00 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> On macOS, handle the case where `writev()` is given an array of `struct iovec` the sum of whose `iov_len` fields overflows `INT_MAX`.

The `writev()` function on Linux is specified to fail if:

     EINVAL The sum of the iov_len values in the iov array would
            overflow an ssize_t.

and similarly on macOS:

     [EINVAL] The sum of the iov_len values in the iov array
              overflows a 32-bit integer.


On Linux, `writev()` was observed _not_ to fail for this case but to return `0x7ffff000`, the maximum number of bytes that `sendfile()` can transfer. This of course might not be the case on all Linux variants.

The error could be handled by a code change in `IOUtil` but then it would affect all platforms. Also, on macOS the problem has only been observed on one version of the operating system so the added native code would not be always be called even though compiled. It would however probably be harmless to conditionally compile the code for Linux as well as macOS.

Testing has verified the fix on macOS 11.6 and earlier macOS versions with no effect (of course) on Linux.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5831


More information about the nio-dev mailing list