Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/scripts/extract_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@

# Github Runners OSS
OSS = {
"ubuntu-latest": ["linux", "amd64"],
"ubuntu-24.04": ["linux", "amd64"],
"ubuntu-24.04-arm": ["linux", "aarch64"],
"windows-latest": ["windows", "amd64"]
}

# Override unavailable Python versions for some OS/Arch / job name combinations
PYTHON_VERSIONS = {
"ubuntu-24.04-arm": "3.12.8",
"ubuntu-latest": "3.12.8",
"ubuntu-24.04": "3.12.8",
"style-gate": "3.8.12",
"style-ecj-gate": "3.8.12",
}
Expand Down Expand Up @@ -119,7 +119,7 @@ def runs_on(self) -> str:
for os, caps in OSS.items():
if all(required in capabilities for required in caps): return os

return "ubuntu-latest"
return "ubuntu-24.04"

@cached_property
def name(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -37,6 +37,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import errno
import unittest
import shutil
import io
Expand Down Expand Up @@ -88,13 +89,12 @@ def test_disk_usage_raises_exception_when_given_path_type_is_not_supported(self)

def test_disk_usage_raises_exception_when_given_path_does_not_exist(self):
not_existing_path = __file__ + '.not-existing'
not_existing_file_name = os.path.basename(not_existing_path)

with self.assertRaisesRegex(FileNotFoundError, rf"No such file or directory: '.+{not_existing_file_name}'"):
with self.assertRaises(FileNotFoundError) as caught:
shutil.disk_usage(not_existing_path)
self.assertEqual(caught.exception.errno, errno.ENOENT)

def test_disk_usage_raises_exception_when_there_is_no_open_file_with_given_file_descriptor(self):
not_existing_file_descriptor = 1_000_000 # expect the current process to not open 1M files

with self.assertRaisesRegex(OSError, r'(B|b)ad file descriptor: 1000000'):
shutil.disk_usage(not_existing_file_descriptor)
shutil.disk_usage(not_existing_file_descriptor)
75 changes: 75 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,88 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import errno
import os
import socket
import struct
import sys
import threading
import unittest

from tests.util import storage_to_native


@unittest.skipUnless(sys.platform == "win32", "Windows socket errors")
class TestWindowsSocketErrors(unittest.TestCase):
def test_strerror_uses_crt_messages(self):
# Winsock messages belong to socket exceptions, not os.strerror().
unknown_error = os.strerror(123456)
for code in (10022, 10054, 10061):
with self.subTest(code=code):
self.assertEqual(os.strerror(code), unknown_error)

def assert_system_message(self, error):
self.assertTrue(error.strerror)
self.assertNotIn("Unknown error", error.strerror)
self.assertEqual(error.strerror, error.strerror.rstrip(" \t\r\n."))

def test_winsock_crt_errno(self):
with socket.socket() as sock:
sock.bind(("127.0.0.1", 0))
with self.assertRaises(OSError) as caught:
sock.bind(("127.0.0.1", 0))
# Winsock duplicates of CRT errors use the CRT errno, retaining winerror.
self.assertEqual(caught.exception.errno, errno.EINVAL)
self.assertEqual(caught.exception.winerror, 10022)
self.assert_system_message(caught.exception)

def test_connection_reset(self):
self.assertEqual(errno.ECONNRESET, 10054)
with socket.socket() as listener:
listener.bind(("127.0.0.1", 0))
listener.listen()
with socket.create_connection(listener.getsockname(), timeout=5) as client:
peer, _ = listener.accept()
with peer:
# Abort the connection rather than sending an orderly EOF.
peer.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("HH", 1, 0))
with self.assertRaises(ConnectionResetError) as caught:
client.recv(1)
self.assertEqual(caught.exception.errno, errno.ECONNRESET)
self.assertEqual(caught.exception.winerror, 10054)
self.assert_system_message(caught.exception)

def test_would_block(self):
self.assertEqual(errno.EWOULDBLOCK, 10035)
self.assertNotEqual(errno.EWOULDBLOCK, errno.EAGAIN)
with socket.socket() as listener:
listener.bind(("127.0.0.1", 0))
listener.listen()
with socket.create_connection(listener.getsockname()) as client:
peer, _ = listener.accept()
with peer:
client.setblocking(False)
with self.assertRaises(BlockingIOError) as caught:
client.recv(1)
self.assertEqual(caught.exception.errno, errno.EWOULDBLOCK)
self.assertEqual(caught.exception.winerror, 10035)
self.assert_system_message(caught.exception)

def test_connection_refused(self):
self.assertEqual(errno.ECONNREFUSED, 10061)
# Keep the port reserved without listening, so another process cannot take it.
with socket.socket() as reserved:
reserved.bind(("127.0.0.1", 0))
for timeout in (None, 5):
with self.subTest(timeout=timeout), socket.socket() as client:
client.settimeout(timeout)
with self.assertRaises(ConnectionRefusedError) as caught:
client.connect(reserved.getsockname())
self.assertEqual(caught.exception.errno, errno.ECONNREFUSED)
self.assertEqual(caught.exception.winerror, 10061)
self.assert_system_message(caught.exception)


def test_shutdown_write_sends_eof():
for how in (socket.SHUT_WR, socket.SHUT_RDWR):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as listener:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import static com.oracle.graal.python.PythonLanguage.getPythonOS;
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_DARWIN;
import static com.oracle.graal.python.annotations.PythonOS.PLATFORM_WIN32;
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
Expand Down Expand Up @@ -95,7 +96,7 @@ public enum OSErrorEnum {
ENOEXEC(8, tsLiteral("Exec format error")),
EBADF(9, tsLiteral("Bad file number")),
ECHILD(10, tsLiteral("No child processes")),
EWOULDBLOCK(platformSpecific(11, 35), tsLiteral("Operation would block")),
EWOULDBLOCK(platformSpecific(11, 35, 10035), tsLiteral("Operation would block")),
EAGAIN(platformSpecific(11, 35), tsLiteral("Try again")),
ENOMEM(12, tsLiteral("Out of memory")),
EACCES(13, tsLiteral("Permission denied")),
Expand Down Expand Up @@ -150,7 +151,7 @@ public enum OSErrorEnum {
ENOSR(platformSpecific(63, 98), tsLiteral("Out of streams resources")),
ENONET(64, tsLiteral("Machine is not on the network")),
ENOPKG(65, tsLiteral("Package not installed")),
EREMOTE(platformSpecific(66, 71), tsLiteral("Object is remote")),
EREMOTE(platformSpecific(66, 71, 10071), tsLiteral("Object is remote")),
ENOLINK(platformSpecific(67, 97), tsLiteral("Link has been severed")),
EADV(68, tsLiteral("Advertise error")),
ESRMNT(69, tsLiteral("Srmount error")),
Expand All @@ -171,43 +172,43 @@ public enum OSErrorEnum {
EILSEQ(platformSpecific(84, 92), tsLiteral("Illegal byte sequence")),
ERESTART(85, tsLiteral("Interrupted system call should be restarted")),
ESTRPIPE(86, tsLiteral("Streams pipe error")),
EUSERS(platformSpecific(87, 68), tsLiteral("Too many users")),
ENOTSOCK(platformSpecific(88, 38), tsLiteral("Socket operation on non-socket")),
EDESTADDRREQ(platformSpecific(89, 39), tsLiteral("Destination address required")),
EMSGSIZE(platformSpecific(90, 40), tsLiteral("Message too long")),
EPROTOTYPE(platformSpecific(91, 41), tsLiteral("Protocol wrong type for socket")),
ENOPROTOOPT(platformSpecific(92, 42), tsLiteral("Protocol not available")),
EPROTONOSUPPORT(platformSpecific(93, 43), tsLiteral("Protocol not supported")),
ESOCKTNOSUPPORT(platformSpecific(94, 44), tsLiteral("Socket type not supported")),
EOPNOTSUPP(platformSpecific(95, 102), tsLiteral("Operation not supported on transport endpoint")),
EUSERS(platformSpecific(87, 68, 10068), tsLiteral("Too many users")),
ENOTSOCK(platformSpecific(88, 38, 10038), tsLiteral("Socket operation on non-socket")),
EDESTADDRREQ(platformSpecific(89, 39, 10039), tsLiteral("Destination address required")),
EMSGSIZE(platformSpecific(90, 40, 10040), tsLiteral("Message too long")),
EPROTOTYPE(platformSpecific(91, 41, 10041), tsLiteral("Protocol wrong type for socket")),
ENOPROTOOPT(platformSpecific(92, 42, 10042), tsLiteral("Protocol not available")),
EPROTONOSUPPORT(platformSpecific(93, 43, 10043), tsLiteral("Protocol not supported")),
ESOCKTNOSUPPORT(platformSpecific(94, 44, 10044), tsLiteral("Socket type not supported")),
EOPNOTSUPP(platformSpecific(95, 102, 10045), tsLiteral("Operation not supported on transport endpoint")),
ENOTSUP(platformSpecific(95, 45), tsLiteral("Operation not supported")),
EPFNOSUPPORT(platformSpecific(96, 46), tsLiteral("Protocol family not supported")),
EAFNOSUPPORT(platformSpecific(97, 47), tsLiteral("Address family not supported by protocol")),
EADDRINUSE(platformSpecific(98, 48), tsLiteral("Address already in use")),
EADDRNOTAVAIL(platformSpecific(99, 49), tsLiteral("Cannot assign requested address")),
ENETDOWN(platformSpecific(100, 50), tsLiteral("Network is down")),
ENETUNREACH(platformSpecific(101, 51), tsLiteral("Network is unreachable")),
ENETRESET(platformSpecific(102, 52), tsLiteral("Network dropped connection because of reset")),
ECONNABORTED(platformSpecific(103, 53), tsLiteral("Software caused connection abort")),
ECONNRESET(platformSpecific(104, 54), tsLiteral("Connection reset by peer")),
ENOBUFS(platformSpecific(105, 55), tsLiteral("No buffer space available")),
EISCONN(platformSpecific(106, 56), tsLiteral("Transport endpoint is already connected")),
ENOTCONN(platformSpecific(107, 57), tsLiteral("Transport endpoint is not connected")),
ESHUTDOWN(platformSpecific(108, 58), tsLiteral("Cannot send after transport endpoint shutdown")),
ETOOMANYREFS(platformSpecific(109, 59), tsLiteral("Too many references: cannot splice")),
ETIMEDOUT(platformSpecific(110, 60), tsLiteral("Connection timed out")),
ECONNREFUSED(platformSpecific(111, 61), tsLiteral("Connection refused")),
EHOSTDOWN(platformSpecific(112, 64), tsLiteral("Host is down")),
EHOSTUNREACH(platformSpecific(113, 65), tsLiteral("No route to host")),
EALREADY(platformSpecific(114, 37), tsLiteral("Operation already in progress")),
EINPROGRESS(platformSpecific(115, 36), tsLiteral("Operation now in progress")),
ESTALE(platformSpecific(116, 70), tsLiteral("Stale file handle")),
EPFNOSUPPORT(platformSpecific(96, 46, 10046), tsLiteral("Protocol family not supported")),
EAFNOSUPPORT(platformSpecific(97, 47, 10047), tsLiteral("Address family not supported by protocol")),
EADDRINUSE(platformSpecific(98, 48, 10048), tsLiteral("Address already in use")),
EADDRNOTAVAIL(platformSpecific(99, 49, 10049), tsLiteral("Cannot assign requested address")),
ENETDOWN(platformSpecific(100, 50, 10050), tsLiteral("Network is down")),
ENETUNREACH(platformSpecific(101, 51, 10051), tsLiteral("Network is unreachable")),
ENETRESET(platformSpecific(102, 52, 10052), tsLiteral("Network dropped connection because of reset")),
ECONNABORTED(platformSpecific(103, 53, 10053), tsLiteral("Software caused connection abort")),
ECONNRESET(platformSpecific(104, 54, 10054), tsLiteral("Connection reset by peer")),
ENOBUFS(platformSpecific(105, 55, 10055), tsLiteral("No buffer space available")),
EISCONN(platformSpecific(106, 56, 10056), tsLiteral("Transport endpoint is already connected")),
ENOTCONN(platformSpecific(107, 57, 10057), tsLiteral("Transport endpoint is not connected")),
ESHUTDOWN(platformSpecific(108, 58, 10058), tsLiteral("Cannot send after transport endpoint shutdown")),
ETOOMANYREFS(platformSpecific(109, 59, 10059), tsLiteral("Too many references: cannot splice")),
ETIMEDOUT(platformSpecific(110, 60, 10060), tsLiteral("Connection timed out")),
ECONNREFUSED(platformSpecific(111, 61, 10061), tsLiteral("Connection refused")),
EHOSTDOWN(platformSpecific(112, 64, 10064), tsLiteral("Host is down")),
EHOSTUNREACH(platformSpecific(113, 65, 10065), tsLiteral("No route to host")),
EALREADY(platformSpecific(114, 37, 10037), tsLiteral("Operation already in progress")),
EINPROGRESS(platformSpecific(115, 36, 10036), tsLiteral("Operation now in progress")),
ESTALE(platformSpecific(116, 70, 10070), tsLiteral("Stale file handle")),
EUCLEAN(117, tsLiteral("Structure needs cleaning")),
ENOTNAM(118, tsLiteral("Not a XENIX named type file")),
ENAVAIL(119, tsLiteral("No XENIX semaphores available")),
EISNAM(120, tsLiteral("Is a named type file")),
EREMOTEIO(121, tsLiteral("Remote I/O error")),
EDQUOT(platformSpecific(122, 69), tsLiteral("Quota exceeded")),
EDQUOT(platformSpecific(122, 69, 10069), tsLiteral("Quota exceeded")),
ENOMEDIUM(123, tsLiteral("No medium found")),
EMEDIUMTYPE(124, tsLiteral("Wrong medium type")),
ECANCELED(platformSpecific(125, 89), tsLiteral("Operation Canceled")),
Expand Down Expand Up @@ -385,6 +386,10 @@ private static int platformSpecific(int linuxValue, int darwinValue) {
return getPythonOS() == PLATFORM_DARWIN ? darwinValue : linuxValue;
}

private static int platformSpecific(int linuxValue, int darwinValue, int windowsValue) {
return getPythonOS() == PLATFORM_WIN32 ? windowsValue : platformSpecific(linuxValue, darwinValue);
}

public static class OperationWouldBlockException extends IllegalStateException {
private static final long serialVersionUID = -6947337041526311362L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EBADF;
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EINPROGRESS;
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EWOULDBLOCK;
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EINTR;
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.EISCONN;
import static com.oracle.graal.python.builtins.objects.exception.OSErrorEnum.ENOTSOCK;
Expand Down Expand Up @@ -437,7 +438,10 @@ static void doConnect(Frame frame, Node inliningTarget, PConstructAndRaiseNode.L
PythonContext.triggerAsyncActions(constructAndRaiseNode);
waitConnect = self.getTimeoutNs() != 0 && isSelectable(self);
} else {
waitConnect = self.getTimeoutNs() > 0 && e.hasErrno(EINPROGRESS) && isSelectable(self);
// Winsock reports WSAEWOULDBLOCK for a nonblocking connection in progress.
boolean inProgress = e.hasErrno(EINPROGRESS) ||
(PythonLanguage.getPythonOS() == PythonOS.PLATFORM_WIN32 && e.hasErrno(EWOULDBLOCK));
waitConnect = self.getTimeoutNs() > 0 && inProgress && isSelectable(self);
}
if (waitConnect) {
SocketUtils.callSocketFunctionWithRetry(frame, inliningTarget, constructAndRaiseNode, posixSupport, gil, self,
Expand All @@ -446,7 +450,7 @@ static void doConnect(Frame frame, Node inliningTarget, PConstructAndRaiseNode.L
s.getsockopt(self.getFd(), SOL_SOCKET.value, SO_ERROR.value, tmp, tmp.length);
int err = PythonUtils.ARRAY_ACCESSOR.getInt(tmp, 0);
if (err != 0 && err != EISCONN.getNumber()) {
throw new PosixErrnoException(err, s.strerror(err));
throw new PosixErrnoException(err, PosixConstants.IS_WIN32 ? s.winerror(err) : s.strerror(err), PosixConstants.IS_WIN32 ? err : null);
}
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ public TruffleString strerror(int errorCode) {
return err.getMessage();
}

@Override
@TruffleBoundary
public TruffleString winerror(int errorCode) {
// Without native access, use the same best-effort messages as strerror.
return strerror(errorCode);
}

@Override
@TruffleBoundary
public int close(int fd) throws PosixException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ public final TruffleString strerror(int errorCode) {
return logExit(Level.FINEST, "strerror", "%s", delegate.strerror(errorCode));
}

@Override
@TruffleBoundary
public final TruffleString winerror(int errorCode) {
logEnter(Level.FINEST, "winerror", "%d", errorCode);
return logExit(Level.FINEST, "winerror", "%s", delegate.winerror(errorCode));
}

@Override
@TruffleBoundary
public final long getpid() {
Expand Down
Loading
Loading