Skip to content

Feature: tcp connect timeot#1

Merged
sedawwk merged 2 commits into
masterfrom
feature/tcp-connect-timeot
Jul 3, 2026
Merged

Feature: tcp connect timeot#1
sedawwk merged 2 commits into
masterfrom
feature/tcp-connect-timeot

Conversation

@heshaoqiong-tuya

Copy link
Copy Markdown
Collaborator
  • Give the PAL tcp_connect callback a caller-supplied timeout so a stalled TCP
    connect can no longer hang the caller on the OS default (tens of seconds). The
    POSIX and FreeRTOS/lwIP implementations now do a non-blocking connect bounded
    by select() and restore blocking mode afterwards; 0 = non-blocking single
    attempt, matching the tcp_send/tcp_recv convention. The loopback test double
    ignores the new parameter.

  • Wire the timeout through every call site: ai-tcp passes connect_timeout_ms,
    HTTP passes the request timeout, MQTT gets a new MQTT_CONNECT_TIMEOUT_MS.

  • Collapse tls_config_t's two timeouts into one: connect_timeout_ms now bounds
    the TCP connect AND the TLS handshake as a single establishment deadline,
    removing handshake_timeout_ms / TLS_DEFAULT_HANDSHAKE_TIMEOUT_MS. tls_connect
    therefore returns within ~one budget regardless of which phase stalls, which
    also restores tai_connect's documented ~2x worst case.

heshaoqiong-tuya and others added 2 commits July 3, 2026 15:13
…eout

Give the PAL tcp_connect callback a caller-supplied timeout so a stalled TCP
connect can no longer hang the caller on the OS default (tens of seconds). The
POSIX and FreeRTOS/lwIP implementations now do a non-blocking connect bounded
by select() and restore blocking mode afterwards; 0 = non-blocking single
attempt, matching the tcp_send/tcp_recv convention. The loopback test double
ignores the new parameter.

Wire the timeout through every call site: ai-tcp passes connect_timeout_ms,
HTTP passes the request timeout, MQTT gets a new MQTT_CONNECT_TIMEOUT_MS.

Collapse tls_config_t's two timeouts into one: connect_timeout_ms now bounds
the TCP connect AND the TLS handshake as a single establishment deadline,
removing handshake_timeout_ms / TLS_DEFAULT_HANDSHAKE_TIMEOUT_MS. tls_connect
therefore returns within ~one budget regardless of which phase stalls, which
also restores tai_connect's documented ~2x worst case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dns_test, atop_test and ota_test forked their Python mock then slept a fixed
1-2s before connecting. On a loaded CI runner the mock isn't accepting yet when
that sleep expires; the first real connect then races its startup. This was
harmless while tcp_connect blocked on the OS default, but now that tcp_connect
is time-bounded the racing connect times out and the test fails (only the later,
mock-dependent cases; the param/failure cases still pass).

Replace the blind sleep with the wait_for_port() readiness probe already proven
in on_boarding_test (which uses the same mocks and passes): a non-blocking
connect probe that returns once the port genuinely accepts, up to 15s. No SDK
change -- this is purely a test-harness startup race.

Verified: all three suites pass locally, and a slow-mock simulation confirms the
probe waits ~until the port binds instead of failing fast.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@heshaoqiong-tuya heshaoqiong-tuya force-pushed the feature/tcp-connect-timeot branch from 11088d8 to 2f19809 Compare July 3, 2026 07:13
@sedawwk sedawwk merged commit 7a4d48e into master Jul 3, 2026
8 checks passed
heshaoqiong-tuya pushed a commit that referenced this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants