Consistently reject illegal values in configuration setters

Open
#173 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust

Research direction

Start by locating the listed configuration setters and comparing them with the existing with_max_connection_age assertion. Review the DeadlinePolicy min/max behavior and axum integration equivalent, then ensure each constrained setter consistently rejects illegal values or documents its exception; leave with_max_connection_age_grace accepting zero.

Written by the indexing model from the issue text.

Description

Summary

Configuration setters across the crate are inconsistent about validating their arguments. Most accept any value silently; a few clamp at the point of use; and (after #165) BoundServer::with_max_connection_age / Server::with_max_connection_age now reject a zero Duration with a panic. We should make this consistent: setters that take a value with an illegal range should reject the illegal value the same way, rather than silently misbehaving in production.

Background

std::time::Duration is unsigned, so it can never be negative — the only out-of-range value for a duration is zero. So "validate" here means "reject zero where zero is illegal" (and any other type-specific illegal values for non-Duration config).

#165 added with_max_connection_age, where a zero duration would turn the server into a connection shredder (every connection retired the instant it starts serving). That setter now assert!s a non-zero duration. The other setters have not been brought into line.

Setters to review

  • Server::with_tls_handshake_timeout / BoundServer::with_tls_handshake_timeout / the axum integration equivalent — a zero handshake timeout is pathological (every TLS handshake times out immediately); currently unguarded.
  • DeadlinePolicy::with_default_timeout — zero likely illegal.
  • DeadlinePolicy::with_inter_message_timeout — zero likely illegal.
  • DeadlinePolicy::with_min / with_max — these already clamp at the point of use; decide whether to also reject obviously-illegal inputs (e.g. min > max) at set time, or leave the clamp.

Note: with_max_connection_age_grace intentionally accepts zero — a zero grace means "GOAWAY then close immediately, no drain window," which is a legitimate choice — so it should not be guarded.

Decision needed

Pick one rejection mechanism and apply it consistently:

  • Panic (assert!) at set time — fail-fast, keeps the chainable -> Self builder shape. This is what with_max_connection_age now does.
  • Clamp / treat-as-disabled at use — the pattern DeadlinePolicy already uses for min/max.

A Result-returning setter would break the chainable builder API, so it is probably not the right fit.

Acceptance

Each value-range-constrained config setter either rejects illegal input consistently (matching the chosen mechanism) or documents why it intentionally accepts the full range.

Dominant language
Rust
Stars
544
Forks
77
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from connectrpc/connect-rust

All issues in connectrpc/connect-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.