Skip to content

Close a connection attempt still in flight when the client is destroyed - #34

Merged
JakaMohorko merged 2 commits into
openDAQ:mainfrom
dejancrn:fix/close-pending-connect
Nov 24, 2026
Merged

JakaMohorko merged 2 commits into
openDAQ:mainfrom
dejancrn:fix/close-pending-connect

Conversation

@dejancrn

Copy link
Copy Markdown
Contributor

Brief

Close a connection attempt that is still pending when Client is destroyed, so an owner that lets its io_context run out of work does not wait for the peer or the system to give up on the attempt.

Description

The Client destructor cancelled only the connection timeout timer. The handler of a pending connect or handshake holds its own reference to the stream, and the timer that would have cancelled the attempt was the one just cancelled, so the attempt stayed pending until the peer answered or the system gave up. An owner that drains its io_context (waits for run() to return once the pending operations have unwound) then waited for it.

The destructor now posts a close of the stream to the io_context. The stream member is only set between the start of a connect and the creation of the session, so an established session is not affected.

openDAQ/openDAQ#1386 depends on this: it drains the native streaming client's transport thread on shutdown instead of stopping it, and without this change removing a device that is connecting to a host that does not answer waits for the stop timeout. That pull request needs a library release that contains this fix.

The destructor cancelled only the connection timeout timer. The handler of a pending connect or handshake holds its own reference to the stream, and the timer that would have cancelled the attempt was the one just cancelled, so the attempt stayed pending until the peer answered or the system gave up. An owner that lets its io_context run until the pending operations have unwound then waited for it. The destructor now posts a close of the stream to the io_context; the stream member is only set between the start of a connect and the creation of the session, so an established session is not affected.
@JakaMohorko JakaMohorko self-assigned this Nov 24, 2026
@JakaMohorko JakaMohorko added the enhancement New feature or request label Nov 24, 2026
@JakaMohorko
JakaMohorko merged commit 89f76e3 into openDAQ:main Nov 24, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants