Skip to content

Tests that compare thread lists fail when they are the first to use Timeout #739

Done

Description

@yorzi

Describe the bug

Five tests compare Thread.list before and after a step. Timeout.timeout starts one thread for the process on first use and keeps it, and StreamableHTTPTransport calls it for every bounded stream write. When one of the five is the first test in the process to reach that call, it counts the Timeout thread as one the transport started, and fails. Whether that happens depends on the seed only.

In test/mcp/server/transports/streamable_http_transport_test.rb:

  • listen keepalive ends with its slot on transport close
  • listen keepalive ends with its slot when a delivery write fails
  • listen keepalive is not started when the interval is nil

In test/mcp/server/transports/streamable_http_stream_request_notifications_test.rb:

  • a response the client does not read ends the request after stream_write_timeout
  • a response the client stops reading part way is cut there, and nothing is written after it

It failed the Ruby 3.1 job of #736 (seed 50208) and the Ruby 3.4 job of #738 (seed 25473). The latter also cancelled the jobs still running.

To Reproduce

On main (bafdca4), run one of them alone:

$ bundle exec ruby -Ilib -Itest test/mcp/server/transports/streamable_http_transport_test.rb -n test_listen_keepalive_ends_with_its_slot_on_transport_close
$ bundle exec ruby -Ilib -Itest test/mcp/server/transports/streamable_http_stream_request_notifications_test.rb -n test_a_response_the_client_does_not_read_ends_the_request_after_stream_write_timeout

Expected behavior

The tests pass in any order, and alone.

Logs

Expected: 2
  Actual: 3
Expected [#<Thread:0x00000001254c59c0@Timeout stdlib thread .../gems/timeout-0.6.1/lib/timeout.rb:87 sleep_forever>] to be empty.

Ruby 4.0.9, timeout 0.6.1.

Additional context

I ran each of the 406 tests of the two files in a process of its own on main: these five fail, and none fails when the Timeout thread is started first.

I have a fix in test/test_helper.rb and will open a PR for it.

Activity

  1. added
    bug
    on Dec 1, 2026
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