Skip to content

Transport constructors accept invalid timeouts and round limits #735

Backlog

Description

@yorzi

Describe the bug

Seven duration options and MCP::Client.new(input_required_max_rounds:) let through values that only fail later, or that do nothing useful:

  1. server_to_client_request_timeout, listen_keepalive_interval, stream_write_timeout and max_stream_lifetime of StreamableHTTPTransport, and max_reconnection_wait of MCP::Client::HTTP, accept Float::INFINITY. session_idle_timeout also accepts NaN.
  2. read_timeout of MCP::Client::Stdio is not checked at all, so Float::INFINITY, negative numbers and strings are accepted.
  3. input_required_max_rounds is not checked either, so nil and NaN are accepted.

An infinite wait is not an unbounded one: ConditionVariable#wait and IO#wait_readable raise RangeError. With stream_write_timeout: Float::INFINITY, Timeout.timeout(Float::INFINITY) ends the process-wide timeout thread with the same error (timeout 0.6.1). OAuth::TokenVerifier and RequestStateSecurity already refuse non-finite durations.

To Reproduce

Save as repro.rb in the repository root and run bundle exec ruby -Ilib repro.rb on main (bafdca4):

require "mcp"
require "mcp/client"
require "mcp/client/http"
require "mcp/client/stdio"

def attempt(label)
  yield
  puts "#{label}: accepted"
rescue => e
  puts "#{label}: #{e.class}: #{e.message}"
end

Transport = MCP::Server::Transports::StreamableHTTPTransport
server = MCP::Server.new(name: "repro", version: "1.0")

# 1. Accepted by the constructor, although the wait each of them feeds cannot use it.
attempt("server_to_client_request_timeout: Infinity") { Transport.new(server, server_to_client_request_timeout: Float::INFINITY).close }
attempt("listen_keepalive_interval: Infinity") { Transport.new(server, listen_keepalive_interval: Float::INFINITY).close }
attempt("stream_write_timeout: Infinity") { Transport.new(server, stream_write_timeout: Float::INFINITY).close }
attempt("max_reconnection_wait: Infinity") { MCP::Client::HTTP.new(url: "http://localhost", max_reconnection_wait: Float::INFINITY) }
attempt("read_timeout: Infinity") { MCP::Client::Stdio.new(command: "ruby", read_timeout: Float::INFINITY) }

# 2. Values that are not durations or round counts.
attempt("session_idle_timeout: NaN") { Transport.new(server, session_idle_timeout: Float::NAN).close }
attempt("read_timeout: -1") { MCP::Client::Stdio.new(command: "ruby", read_timeout: -1) }
attempt("input_required_max_rounds: nil") { MCP::Client.new(transport: Object.new, input_required_max_rounds: nil) }

# 3. What an infinite wait does at run time.
attempt("ConditionVariable#wait(Infinity)") { Mutex.new.tap { |m| m.synchronize { ConditionVariable.new.wait(m, Float::INFINITY) } } }
attempt("IO#wait_readable(Infinity)") { IO.pipe.first.wait_readable(Float::INFINITY) }

Expected behavior

The constructors raise ArgumentError. A duration is a positive finite number, or nil where the option documents it. input_required_max_rounds is a non-negative Integer: 0 works today and leaves every input_required result to the caller.

Logs

server_to_client_request_timeout: Infinity: accepted
listen_keepalive_interval: Infinity: accepted
stream_write_timeout: Infinity: accepted
max_reconnection_wait: Infinity: accepted
read_timeout: Infinity: accepted
session_idle_timeout: NaN: accepted
read_timeout: -1: accepted
input_required_max_rounds: nil: accepted
ConditionVariable#wait(Infinity): RangeError: Inf out of Time range
IO#wait_readable(Infinity): RangeError: Inf out of Time range

Ruby 4.0.9.

Additional context

Some of these values do have an effect today:

  • session_idle_timeout: Float::INFINITY, Float::NAN and false disable expiry. nil is the documented way to ask for that.
  • max_stream_lifetime and stream_write_timeout: Float::INFINITY means no limit, as the documented nil does.
  • read_timeout: false means no timeout, as nil does.
  • listen_keepalive_interval: Float::INFINITY works on streams with a deadline. A large finite number does the same; nil does not, since a quiet stream then stays open past its deadline.
  • input_required_max_rounds: a Float or Rational is rounded down, Float::INFINITY and Float::NAN mean no cap, and a negative number behaves like 0. An Integer replaces each of them; nil is not accepted.

I suggest refusing them like the others.

The per-call timeout: of server-to-client requests is not checked either. It is left for a separate change.

I have a fix with tests and will open a PR for it.

Activity

  1. added
    bug
    on Dec 1, 2026
  2. added a commit that references this issue on Dec 1, 2026
    bcc5ea4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions