Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcp_socket:connect(addr, ip) to a listening server returns timeout if timeout is set to 0 on macOS. #431

Open
dljsjr opened this issue May 29, 2024 · 0 comments

Comments

@dljsjr
Copy link

dljsjr commented May 29, 2024

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:

  1. If we call connect for an address that isn't listening, we'll get timeout. A subsequent call to select with the client in the send position will return immediately with no error, but the socket isn't connected.
  2. If we call connect for an address that is listening, we still get timeout, 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


@dljsjr dljsjr changed the title tcp_socket:connect(addr, ip) to a listening server returns timeout if timeout is set to 0. tcp_socket:connect(addr, ip) to a listening server returns timeout if timeout is set to 0 on macOS. May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant