-
Notifications
You must be signed in to change notification settings - Fork 647
Description
This seems to be a macOS specific situation, and I'm not sure if it's a regression in a newer macOS or not. I've only just recently discovered this, and I'm running Sonoma, so it's definitely present in the latest macOS.
This is using luasocket as installed from luarocks
🍎 ❯ luarocks list
Rocks installed for Lua 5.3
---------------------------
luasec
1.3.2-1 (installed) - /Users/dougstephen/.luarocks/lib/luarocks/rocks-5.3
luasocket
3.1.0-1 (installed) - /Users/dougstephen/.luarocks/lib/luarocks/rocks-5.3
The repro case is pretty simple; Use socket.tcp() to create a master socket, call tcp_socket:settimeout(0), then call tcp_socket:connect(addr, port) on a known listening server socket.
Since we know the remote socket is up, we would expect the connect to succed. Instead, we receive nil, 'timeout'.
Looking at the docs, we know that we should select a socket that returns timeout after connect. But there's too much ambiguity here:
- If we call
connectfor an address that isn't listening, we'll gettimeout. A subsequent call toselectwith the client in the send position will return immediately with no error, but the socket isn't connected. - If we call
connectfor an address that is listening, we still gettimeout, and the select behavior is the exact same as if the address didn't exist at all.
In other words, we can't know that the connection failed until we try to use the socket, which seems less than ideal.
I've attached a tarball with the scripts I used, and screen recordings of both macOS and Linux execution behavior for the attached scripts. Under Linux, we get the expected behavior.
Attachments
- scripts: luasocket-repro.tar.gz
- macOS Screen Recording: https://github.com/lunarmodules/luasocket/assets/444635/efb9e6a8-ba95-44e5-9e07-829afc4e2139
- Linux Screen Recording: https://github.com/lunarmodules/luasocket/assets/444635/90613a76-d761-43ab-b6e1-f3151d58c283