Skip to content

Add non-spawning create variants for TCP/TLS/serial clients#180

Merged
jadamcrain merged 1 commit into
mainfrom
feature/non-spawning-client-tasks
May 28, 2026
Merged

Add non-spawning create variants for TCP/TLS/serial clients#180
jadamcrain merged 1 commit into
mainfrom
feature/non-spawning-client-tasks

Conversation

@jadamcrain
Copy link
Copy Markdown
Member

Summary

Adds non-spawning (create_*) variants of the client channel constructors alongside the existing spawn_* functions, so callers can spawn the channel task on their own runtime and attach their own tracing instrumentation.

New public functions:

  • create_tcp_client_task_with_options(host, retry, listener, client_options) -> (Channel, ClientTask)
  • create_tls_client_task_with_options(host, retry, tls_config, listener, client_options) -> (Channel, ClientTask) (enable-tls)
  • create_rtu_client_task(path, serial_settings, max_queued_requests, retry, decode, listener) -> (Channel, ClientTask) (serial)

Design

  • ClientTask is a single opaque public type shared across all three transports — internally an enum over TcpChannelTask/SerialChannelTask — exposing only pub async fn run(self). No boxing.
  • The default tracing spans were moved out of the create_*_channel helpers and into the spawn_* functions, so created tasks carry no span and the caller is free to wrap ClientTask::run with their own instrumentation, e.g. tokio::spawn(task.run().instrument(my_span)).
  • Task construction is now eager (the task struct is built in create_* rather than inside an async move block). This is a pure struct build with no I/O; connection state transitions still happen in run().

Bug fix

The TLS connection path was labeling its tracing span "Modbus-Client-TCP"; it is now correctly "Modbus-Client-TLS".

Verification

cargo fmt, cargo check, and cargo clippy all pass clean with --features serial,enable-tls. Reviewed by Codex with no correctness findings.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new ClientTask type and corresponding create_* functions (create_tcp_client_task_with_options, create_rtu_client_task, and create_tls_client_task_with_options) to allow creating Modbus client tasks without spawning them immediately. This allows callers to apply custom instrumentation before spawning. The review feedback suggests optimizing spawn_tcp_channel and spawn_tls_channel to avoid cloning host (which can cause heap allocations) by creating the tracing span first and then moving host into the channel creation functions.

Comment thread rodbus/src/tcp/client.rs Outdated
Comment thread rodbus/src/tcp/tls/client.rs Outdated
Adds create_tcp_client_task_with_options, create_tls_client_task_with_options,
and create_rtu_client_task, each returning (Channel, ClientTask) so the caller
can spawn the task on their own runtime and attach their own tracing
instrumentation.

ClientTask is a single opaque type shared across all three transports
(an internal enum over TcpChannelTask/SerialChannelTask) exposing only
`async fn run(self)`. The default tracing spans now live in the spawn_*
functions rather than the create_*_channel helpers, so created tasks carry
no span. Also fixes the TLS path span name (was "Modbus-Client-TCP").
@jadamcrain jadamcrain force-pushed the feature/non-spawning-client-tasks branch from 7c7d42a to b197780 Compare May 28, 2026 20:31
@jadamcrain jadamcrain merged commit bdaf21a into main May 28, 2026
24 checks passed
@jadamcrain jadamcrain deleted the feature/non-spawning-client-tasks branch May 28, 2026 20:35
@jadamcrain jadamcrain mentioned this pull request May 28, 2026
jadamcrain added a commit that referenced this pull request May 28, 2026
* release 1.5.0-RC2

Bump workspace version 1.5.0-RC1 -> 1.5.0-RC2 across all crates, bindings,
and the guide, and refresh Cargo.lock.

Collapse the 1.5.0 and 1.5.0-RC1 changelog sections into a single
1.5.0-RC2 section and add the non-spawning client task entry (#180).

* derive rodbus-client CLI version from CARGO_PKG_VERSION

Avoids manually bumping the hardcoded version string on every release.

* changelog: add TCP client performance optimizations (#177)

Also note the ReadBuffer shift-condition fix from the same PR. These landed
after 1.5.0-RC1 and were missing from the release notes.

* changelog: clarify ReadBuffer fix impact (rare spurious disconnect)
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