From 5d86d0aa2cd53f9733ae04518199933e2078e51e Mon Sep 17 00:00:00 2001 From: Raekye Date: Mon, 22 Sep 2025 15:31:36 -0400 Subject: [PATCH] Handle UDP bind -> listen EACCES. `IO::Endpoint::Wrapper.bind` always calls `Socket#listen`, and handles `Errno::EOPNOTSUPP`, for example for UDP sockets, for which the `listen` call is not applicable (see `man 2 listen`). However, in some environments, such as in a container, the error may be mapped to `EACCES`, which can be verified with a simple C program. This patch ignores `Errno::EACCES` if it was a UDP socket, since the `listen` call was meaningless in the first place. --- lib/io/endpoint/wrapper.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/io/endpoint/wrapper.rb b/lib/io/endpoint/wrapper.rb index a2adba4..00e66e3 100644 --- a/lib/io/endpoint/wrapper.rb +++ b/lib/io/endpoint/wrapper.rb @@ -157,6 +157,13 @@ def bind(local_address, protocol: 0, reuse_address: true, reuse_port: nil, linge socket.listen(backlog) rescue Errno::EOPNOTSUPP # Ignore. + rescue Errno::EACCES + # Unfortunately, in some environments, the error gets translated to "permission denied" instead. + if local_address.socktype == ServerSocket::SOCK_DGRAM + # Ignore + else + raise + end end end rescue