The tests test/jdk/java/nio/channels/SocketChannel/OpenLeak.java and test/jdk/java/nio/channels/SocketChannel/CloseDuringConnect.java when running on macos 26 have been consistently running into "java.net.SocketException: No buffer space available" exception causing these tests to fail. The exception stacktrace looks like:
Caused by: java.net.SocketException: No buffer space available
at java.base/sun.nio.ch.Net.socket0(Native Method)
at java.base/sun.nio.ch.Net.socket(Net.java:491)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:155)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:138)
at java.base/sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:77)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:192)
at CloseDuringConnect.test(CloseDuringConnect.java:98)
and
Caused by: java.net.SocketException: No buffer space available
at java.base/sun.nio.ch.Net.socket0(Native Method)
at java.base/sun.nio.ch.Net.socket(Net.java:491)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:155)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:138)
at java.base/sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:77)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:192)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:274)
at OpenLeak.lambda$test$0(OpenLeak.java:122)
These have been failing only on macos 26.x and not on any older versions of macos (or any other OS).
After investigating this a bit, I created a native C reproducer (attached) which consistently reproduces this issue on macos 26.x (on the older macos versions, the reproducer completes normally):
#include <stdio.h>
#include <sys/socket.h>
#include <string.h>
#include <unistd.h>
#include <sys/errno.h>
static int create_socket(const int attempt_number) {
const int fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd < 0) {
fprintf(stderr, "socket creation failed on attempt %d,"
" due to: %s\n", attempt_number, strerror(errno));
return fd;
}
return fd;
}
int main() {
const unsigned int num_times = 250000;
for (unsigned int i = 1; i <= num_times; i++) {
const int fd = create_socket(i);
if (fd < 0) {
return -1;
}
close(fd);
}
fprintf(stderr, "successfully created and closed %d sockets\n", num_times);
}
The code very trivially creates a socket() and close()s it. It does this repeatedly in a loop for a certain number of iterations.
Compiling this as:
clang sockbufspaceerr.c -o sockbufspaceerr.o
and running it as:
./sockbufspaceerr.o
consistently generates an error as follows on macos 26.x:
socket creation failed on attempt 160995, due to: No buffer space available
The iteration number on which the socket() creation fails varies, but the issue does reproduce. Running the same on older versions of macos doesn't reproduce the issue and the program terminates normally after those many iterations.
After discussing this in macos developer forums, the engineers there suggested to file an issue with Apple. I've filed FB21686886 which tracks it in Apple's feedback assistant bug tracking tool.
Caused by: java.net.SocketException: No buffer space available
at java.base/sun.nio.ch.Net.socket0(Native Method)
at java.base/sun.nio.ch.Net.socket(Net.java:491)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:155)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:138)
at java.base/sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:77)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:192)
at CloseDuringConnect.test(CloseDuringConnect.java:98)
and
Caused by: java.net.SocketException: No buffer space available
at java.base/sun.nio.ch.Net.socket0(Native Method)
at java.base/sun.nio.ch.Net.socket(Net.java:491)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:155)
at java.base/sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:138)
at java.base/sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:77)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:192)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:274)
at OpenLeak.lambda$test$0(OpenLeak.java:122)
These have been failing only on macos 26.x and not on any older versions of macos (or any other OS).
After investigating this a bit, I created a native C reproducer (attached) which consistently reproduces this issue on macos 26.x (on the older macos versions, the reproducer completes normally):
#include <stdio.h>
#include <sys/socket.h>
#include <string.h>
#include <unistd.h>
#include <sys/errno.h>
static int create_socket(const int attempt_number) {
const int fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd < 0) {
fprintf(stderr, "socket creation failed on attempt %d,"
" due to: %s\n", attempt_number, strerror(errno));
return fd;
}
return fd;
}
int main() {
const unsigned int num_times = 250000;
for (unsigned int i = 1; i <= num_times; i++) {
const int fd = create_socket(i);
if (fd < 0) {
return -1;
}
close(fd);
}
fprintf(stderr, "successfully created and closed %d sockets\n", num_times);
}
The code very trivially creates a socket() and close()s it. It does this repeatedly in a loop for a certain number of iterations.
Compiling this as:
clang sockbufspaceerr.c -o sockbufspaceerr.o
and running it as:
./sockbufspaceerr.o
consistently generates an error as follows on macos 26.x:
socket creation failed on attempt 160995, due to: No buffer space available
The iteration number on which the socket() creation fails varies, but the issue does reproduce. Running the same on older versions of macos doesn't reproduce the issue and the program terminates normally after those many iterations.
After discussing this in macos developer forums, the engineers there suggested to file an issue with Apple. I've filed FB21686886 which tracks it in Apple's feedback assistant bug tracking tool.
- relates to
-
JDK-8273158 Tests failing with "SocketException: No buffer space available" [macos-aarch64]
-
- In Progress
-