Skip to content

Positive sub-microsecond socket timeouts disable the timeout on POSIX #220

Closed

Description

@dimensionscape

On POSIX, a positive socket timeout shorter than one microsecond is converted to a zero timeval. SO_RCVTIMEO and SO_SNDTIMEO interpret zero as no timeout, so a small positive deadline can turn into an unbounded blocking operation.

Regression coverage first: test/regression/SocketTinyTimeout, in the existing regression layout. Connect two loopback sockets. Have the peer send one byte after 100 ms so the test remains bounded even when the timeout is disabled. A read with timeout 0.0000001 seconds should time out before the byte arrives. Repeat with 0.01 seconds as a control and wait for the sender to finish before closing sockets.

Confirmed on Linux x86_64 with Haxe 4.3.3:

tiny positive timeout expired: false
normal positive timeout expired: true

In src/hx/libs/std/Socket.cpp, socket_set_timeout truncates the fractional part to integer microseconds. The POSIX branch does not ensure that a positive request produces a nonzero timeval. The Windows branch already has the equivalent guard for positive sub-millisecond values.

Round a positive timeout up to the platform's minimum nonzero representation. Keep exactly zero and null as the existing no-timeout setting. Cover values below one microsecond, normal fractional values and the boundary near a full second, and avoid producing an invalid tv_usec of 1000000 through rounding.

The reproduction is Linux-only. This is separate from interrupted select/poll deadlines: the timeout is disabled before the receive operation even starts. No runtime implementation changes are included.

Activity

  1. added a commit that references this issue on Oct 20, 2026
    a707189
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions