Skip to content

Fixed misleading error text on TCP connect timeout - #155

Open
julien-l wants to merge 1 commit into
DCMTK:masterfrom
julien-l:fix-tcp-timeout-error-text
Open

Fixed misleading error text on TCP connect timeout#155
julien-l wants to merge 1 commit into
DCMTK:masterfrom
julien-l:fix-tcp-timeout-error-text

Conversation

@julien-l

Copy link
Copy Markdown

Problem

When a connection attempt times out, requestAssociationTCP() produces a condition text that
claims both failure and success at the same time:

DEBUG: Association Request Failed: 0006:031c TCP Initialization Error: Success (Timeout)

(macOS/Linux; on Windows the same path yields No error (Timeout).)

In dcmnet/libsrc/dulfsm.cc, the non-blocking connect() is awaited with poll()/select().
A return value of 0 means timeout, not error — no error code has been set — but the timeout
branch appended OFStandard::getLastNetworkErrorCode().message() anyway, which renders error
code 0 as "Success" / "No error".

This is the sibling of #129, which fixed the rc < 0 branch by caching the error code before
close()/closesocket() resets it. That fix is in master; the rc == 0 timeout branch still
reports error code 0.

Fix

Drop the error-code text from the timeout branch and report the timeout on its own:

DEBUG: Association Request Failed: 0006:031c TCP Initialization Error: Timeout

One-line change plus a comment explaining why no error code is reported there.

Reproducing

Any SCU with a connect timeout set (DcmSCU::setConnectionTimeout()) against an unreachable
host that silently drops SYN, e.g.:

echoscu --timeout 2 <blackholed-ip> 104 -d

A host that actively refuses gets ECONNREFUSED via the getsockopt(SO_ERROR) branch, so the
bogus text only shows on a genuine timeout.

Observed with 3.6.9 and reproducible on current master; the affected lines are unchanged
in 3.7.0.

When poll()/select() reports a timeout while waiting for a non-blocking
connect() to complete, requestAssociationTCP() appended the last network
error code to the condition text.  No error code has been set in that
case, so the text was that of error code 0, resulting in messages like

  TCP Initialization Error: Success (Timeout)

on POSIX platforms, or "No error (Timeout)" on Windows, which reads as
both a failure and a success at the same time.

Report the timeout on its own instead.  This complements the fix in the
rc < 0 branch (GitHub PR DCMTK#129), which caches the error code before it is
reset by close()/closesocket().
@julien-l
julien-l force-pushed the fix-tcp-timeout-error-text branch from 2a42bf7 to 4278d4b Compare July 30, 2026 19:28
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.

1 participant